I suggest you to follow an example from the web, there are many, just be sure, if you begin with Laravel, to choose one from the same version of Laravel you use (or install the Laravel version from the example)
Laravel CRUD
Hi all I am n newbie in Laravel and have started to create my own application, I would like to know if there is a shorter way in creating CRUD functions with the correct validations in doing create, store, update, delete. I'm struggling to find the right way of doing this , I know some video content can be misleading and you get the shortcut versions, but I would like to do it the right way from the start, Please see my Code
{
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function createEmployee()
{
employee::create([
'name'=> request()->name,
'lastname'=>request()->lastname,
'address'=>request()->address,
'email'=>request()->email,
'jobtitle'=>request()->jobtitle,
]);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function storeEmployee(Request $request)
{
$validated = $request->validate([
'name' => 'required|max:50',
'lasname' => 'required|max:50',
'address' => 'required|max:50',
'email' => 'required|email|unique:email',
'jobtitle' => 'required|max:50'
]);
}
Not sure how to do the update and delete
I suggest following the resource controller approach for naming: https://laravel.com/docs/9.x/controllers#resource-controllers
And use form requests for validation https://laravel.com/docs/9.x/validation#form-request-validation
Please or to participate in this conversation.