I'm trying to pass a variable while routing to the create function in my controller.
<a href="" title="Add color" class="">Add color</a>
CustomerColorController.php
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('customer_color.create');
}
I can only solve this by writing my own route but this is not how it should be:
<a href="" title="Add color" class="px-4 py-2 bg-gray-800 border border-transparent font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring ring-gray-300 disabled:opacity-25 transition ease-in-out duration-150">Add color</a>
Web.php
Route::get('/customercolor/add/{customer_id}', function ($customer_id) {
$colors = Color::get();
$customer = Customer::find($customer_id);
return view('customer_color.create', compact('customer', 'colors'));
});
How do I achieve this with the specified routes? I'm having the same issue when I try to update obviously.
source https://stackoverflow.com/questions/71561072/laravel-create-route-with-variable
No comments:
Post a Comment