download laravel crud project code example
Example 1: laravel crud tutorial
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Ticket;
class TicketController extends Controller
{
public function index()
{
$patients = Patient::where('user_id', auth()->user()->id)->get();
return view('patients.index',compact('patients'));
}
public function create()
{
return view('patients.create');
}
public function store(Request $request)
{
$ticket = new Patient();
$data = $this->validate($request, [
'name'=>'required',
'surname'=> 'required'
'id_number'=> 'required'
]);
$patient->savePatient($data);
return redirect('/home')->with('success', 'New patient has been succesfully created');
}
public function show($id)
{
}
public function edit($id)
{
$patient = Patient::where('user_id', auth()->user()->id)
->where('id', $id)
->first();
return view('patients.edit', compact('patient', 'id'));
}
public function update(Request $request, $id)
{
$patient = new Patient();
$data = $this->validate($request, [
'name'=>'required',
'surname'=> 'required'
'id_number'=> 'required'
]);
$data['id'] = $id;
$patient->updatePatient($data);
return redirect('/home')->with('success', 'Patient Information was updated succesfully');
}
public function destroy($id)
{
$patient = Patient::find($id);
$patient->delete();
return redirect('/home')->with('success', 'The patient has been deleted!!');
}
}
Example 2: laravel crud
$ php artisan make:controller ContactController --resource