I've been getting this error but I'm not sure how I can create this route to solve this problem. Could someone help me create this route in my web.php file. Thank you in advance for taking the time to look at this issue. A great day everyone. Error Image ->
Error -> Text
Symfony\Component\Routing\Exception\RouteNotFoundException
Route [threads.storev] not defined. (View: C:\projetos\forum8\resources\views\threads\createv.blade.php)
http://127.0.0.1:8000/threads/createv
My route in createv.blade.php file
<form action="{{route('threads.storev')}}" method="post" enctype="multipart/form-data">
I'm calling the view with this function.
public function createv()
{
//create thread
return view('threads.createv');
}
storev public function
public function storev(Request $request)
{
try{
$thread = $request->all();
$creds = $request->validate([
'op_post_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'title' => ['required'],
'body' => ['required']
]);
if ($image = $request->file('op_post_image')) {
$destinationPath = 'media/uploads';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$input['op_post_image'] = "$profileImage";
}
$thread = new Thread();
$thread['slug'] = Str::slug($creds['title']);
$thread->title = $creds['title'];
$thread->body = $creds['body'];
$thread->op_post_image = $input['op_post_image'];
$user = Auth::user();
$user->threads()->save($thread);
dd('Tópico criado com sucesso');
} catch (\Exeption $e){
dd($e->getMessage());
}
}
}
My Routes
Route::get('/', function () {
return view('welcome');
});
Route::get('/threads/createv', [App\Http\Controllers\ThreadController::class, 'createv']);
Route::resource('threads', 'App\Http\Controllers\ThreadController');
Auth::routes();
Route::get('/', [App\Http\Controllers\ThreadController::class, 'index'])->name('home');
Route::middleware(['auth', 'verified'])->group(function () {
Route::resource('profile', 'App\Http\Controllers\ProfileUp');
});
CodePudding user response:
Add in your routes file web.php
:
Route::post('/threads/storev', [App\Http\Controllers\ThreadController::class, 'storev'])->name('threads.storev');