I am trying to make a user able to post. I had some errors, but now I do not have any errors, but the store method does not work even though it does not show any errors. This is the form in home.balde.php
<form method="POST" action="{{ url('form-store') }}">
@csrf
<img class="avatar" src="images/uploads/avatars/{{ $user->avatar }}" alt="pic" width="50px">
<label for="ftext">
<input type="text" id="text" name="text" placeholder="What's happening?" style="background-color: transparent; border-color: transparent; color: white;" required>
</label>
<br>
<div class="row">
<div class="col">
<label for="ftopic">
<input type="text" id="topic" name="topic" placeholder="Topic" style="background-color: transparent; border-color: transparent; color: white;" required>
</label>
</div>
<div class="col">
<label for="fhashtag">
<input type="text" id="hashtag" name="hashtag" placeholder="Hashtag" style="background-color: transparent; border-color: transparent; color: white;" required>
</label>
</div>
<div class="col">
<div class="text-end">
<button type="submit" class="tweetBtn">Tweet</button>
</div>
</div>
</div>
</form>
This is the model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tweets extends Model
{
protected $fillable = ['content', 'topic', 'hashtag'];
}
This is HomeController
public function store(Request $request)
{
if (!auth()->check()) {
abort(403, 'Only authenticated users can create new posts.');
}
$data = request()->validate([
'content' => 'required',
'topic' => 'required|email',
'hashtag' => 'required'
]);
$check = Tweets::create($data);
return Redirect::to("form")->withSuccess('Great! Form successfully submit with validation.');
}
And these are the routes in web.php
Route::get('form', 'HomeController@index')->name('form');
Route::post('form-store', 'HomeController@store')->name('form-store');
When I click submit the page will just refresh and nothing happens also in database
Check this code...
Instead of
name="text"
it should bename="content"