php - Lravel 5.1 How to find database records through a from? -


in admin area of app, want have form admin can find project id , show project details there. best approach implement this? have tried:

//route route::get('admin/projects/{project_id}', 'admincontroller@showproject'); //form     {!! form::open(['action' => 'admincontroller@showproject', 'method' => 'get']) !!}         {!! form::label('project_id', 'project id', ['class' => 'control-label']) !!}             {!! form::text('project_id', null, ['class' => 'form-control']) !!}         {!! form::submit('submit', ['class' => 'form-control']) !!}         {!! form::close() !!}  //controller method public function showproject(request $request)     {         $project=project::find($request->get('project_id'));         return view('admin.projects.showproject', compact('project'));     } 

it worked there little problem. after retrieving requested project, ulr this:

admin/projects/%7bproject_id%7d?project_id=5  

i want one:

admin/projects/5 

how can solve problem?

create following routes:

route::get('admin/projects', 'admincontroller@getproject'); route::post('admin/projects', 'admincontroller@postproject'); route::get('admin/projects/{project_id}', 'admincontroller@showproject'); 

in getproject function return view show form user can enter id. (the 1 have):

{!! form::open(['action' => 'admincontroller@postproject', 'method' => 'post']) !!}     {!! form::label('project_id', 'project id', ['class' => 'control-label']) !!}     {!! form::text('project_id', null, ['class' => 'form-control']) !!}     {!! form::submit('submit', ['class' => 'form-control']) !!} {!! form::close() !!} 

in postproject function send redirect admin/project/{project_id} url:

public function postproject(request $request) {     return redirect('admin/projects/' . $request->project_id); } 

in showproject function retrieve record , return view information:

public function showproject($projectid) {     $project=project::find($projectid);     return view('admin.projects.showproject'),         ->with('project', compact('project')); } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -