Al fin luego de mucho luchar ya encontramos la solución de esta duda que muchos usuarios de nuestra web han presentado. Si tienes algún dato que aportar puedes dejar tu conocimiento.
Ejemplo: crud con modal en lravel
namespaceAppHttpControllers;useIlluminateHttpRequest;useAppCustomer;useRedirect,Response;classCustomerControllerextendsController/**
* Display a listing of the resource.
*
* @returnIlluminateHttpResponse
*/publicfunctionindex()$customers=Customer::latest()->paginate(4);returnview('customers.index',compact('customers'))->with('i',(request()->input('page',1)-1)*4);/**
* Show the form for creating a new resource.
*
* @returnIlluminateHttpResponse
*/publicfunctioncreate()returnview('customers.create');/**
* Store a newly created resource in storage.
*
* @paramIlluminateHttpRequest$request
* @returnIlluminateHttpResponse
*/publicfunctionstore(Request$request)$r=$request->validate(['name'=>'required','email'=>'required','address'=>'required',]);$custId=$request->cust_id;Customer::updateOrCreate(['id'=>$custId],['name'=>$request->name,'email'=>$request->email,'address'=>$request->address]);if(empty($request->cust_id))$msg='Customer entry created successfully.';else$msg='Customer data is updated successfully';returnredirect()->route('customers.index')->with('success',$msg);/**
* Display the specified resource.
*
* @paramint$id
* @returnIlluminateHttpResponse
*/publicfunctionshow(Customer$customer)returnview('customers.show',compact('customer'));/**
* Show the form for editing the specified resource.
*
* @paramint$id
* @returnIlluminateHttpResponse
*/publicfunctionedit($id)$where=array('id'=>$id);$customer=Customer::where($where)->first();returnResponse::json($customer);/**
* Update the specified resource in storage.
*
* @paramIlluminateHttpRequest$request
* @paramint$id
* @returnIlluminateHttpResponse
*/publicfunctionupdate(Request$request)/**
* Remove the specified resource from storage.
*
* @paramint$id
* @returnIlluminateHttpResponse
*/publicfunctiondestroy($id)$cust=Customer::where('id',$id)->delete();returnResponse::json($cust);
No se te olvide compartir este tutorial si te ayudó.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)