I have 2 forms, the first is the form motorbikes
with 3 fields (matriculation, number_motorbike, status).
Then, we have the form revisions
with 4 fields (date_revision_start, date_revision_end, garage, fk_motorbike)
Here in the form motorbikes
the status of the number motorbike must to be automatically unavailable
.
I must to work on which controller to automate the availability status of the motorbike?
Motorbike Controller
public function index()
{
$motorbikes = Motorbike::latest()->paginate(5);
return view('admin.motorbikes.index', compact('motorbikes'))
->with('i', (request()->input('page',1) -1)*5);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.motorbikes.create', compact('motorbikes'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$exists = Motorbike::where('matriculation', $request->get('matriculation'))->where('number_motorbike', $request->get('number_motorbike'))->where('status', $request->get('status'))->count();
if (!$exists){
Motorbike::create($request->all());
return redirect()->route('motorbikes.index')
->with('success', 'new data created successfully');
}
else{
return redirect()->route('motorbikes.index')
->with('error', 'doublon');
}
}
Revision Controller
class RevisionController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$revisions = Revision::oldest()->paginate(5);
return view('admin.revisions.index', compact('revisions'))
->with('i', (request()->input('page',1) -1)*5);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$motorbikes = Motorbike::all();
return view('admin.revisions.create', compact('motorbikes','revisions'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'date_revision_start' => 'required|date',
'date_revision_end' => 'required|date',
'garage' => 'required',
'fk_motorbike' => 'required'
]);
$exists = Revision::where('date_revision_start', $request->get('date_revision_start'))->where('date_revision_end', $request->get('date_revision_end'))->where('garage', $request->get('garage'))->where('fk_motorbike', $request->get('fk_motorbike'))->count();
if (!$exists){
Revision::create($request->all());
return redirect()->route('revisions.index')
->with('success', 'new data created successfully');
}
else{
return redirect()->route('revisions.index')
->with('error', 'duplicata');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire