Monday, 15 September 2014

Laravel PHP: Use Dropdown box for displaying results -



Laravel PHP: Use Dropdown box for displaying results -

i have laravel php application , running fine of results created, edited , stored fine. want add together feature there dropdown box on homepage allows user select category , homepage display results depending on user selects dropdown box.

i have tried finding documentation on how accomplish task possible solution found using ajax jquery update results. i'm wondering if there easier, more elegant way of doing this.

view:

@section('content') /* new section added including dropdown box below */ <div class="row"> <div class="panel panel-default"> <div class="panel-heading clearfix"> <b>{{'select category' }}</b> </div> <div class="panel-body"> <dl class="dl-horizontal"> <div class="table-responsive"> <table class="table"> <tr> <td> {{form::open(array('route' => 'select_vids_pics', 'files' => true)) }} <div class="form-group"> /* form code goes here, 'label' , 'select options' */ <div class="form-group"> {{ form::submit('select category', array('class' => 'btn btn-primary')) }} </div> {{ form::close() }} </div> </td> </tr> </table> </div> </dl> </div> </div> </div> /* blocks of code below display results */ <div class="row"> <div class="panel panel-default"> <div class="panel-heading clearfix"> <b>{{'overview of videos' }}</b> </div> <div class="panel-body"> @if ($allvids->count()) <dl class="dl-horizontal"> <!-- add together div class create table responsive --> <div class = "table-responsive"> <table class="table"> <tr> <th>id</th> <th>name</th> <th>description</th> <th>edge</th> <th>stone</th> <th>category</th> <th>project</th> <th>update video</th> </tr> @foreach($allvids $video) <tr> <td>{{ $video->video_id }}</b></td> <td>{{ $video->video_name }}</td> <td>{{ $video->video_description }}</td> <td>{{ $video->video_edges }} </td> <td>{{ $video->video_stones }}</td> <td>{{ $video->category }}</td> <td>{{ $video->video_project }}</td> <td><b>{{ link_to_route("show_video", 'edit', array($video->video_id)) }}</b></td> </tr> @endforeach {{ $allvids-> links()}} </table> </div> </dl> @else <b>{{ 'all pics vids' }}</b> @endif </div> </div> </div> <div class="row"> <div class="panel panel-default"> <div class="panel-heading clearfix"> <b>{{'overview of pictures' }}</b> </div> <div class="panel-body"> @if ($allpics->count()) <dl class="dl-horizontal"> <!-- add together div class create table responsive --> <div class = "table-responsive"> <table class="table"> <tr> <th>id</th> <th>name</th> <th>description</th> <th>edge</th> <th>stone</th> <th>category</th> <th>project</th> <th>update picture</th> </tr> @foreach($allpics $picture) <tr> <td>{{ $picture->picture_id }}</b></td> <td>{{ $picture->picture_name }}</td> <td>{{ $picture->picture_description }}</td> <td>{{ $picture->picture_edges }} </td> <td>{{ $picture->picture_stones }}</td> <td>{{ $picture->category }}</td> <td>{{ $picture->picture_project }}</td> <td><b>{{ link_to_route("show_picture", 'edit', array($picture->picture_id)) }}</b></td> </tr> @endforeach {{ $allpics-> links()}} </table> </div> </dl> @else <b>{{ 'all pics vids' }}</b> @endif </div> </div> </div> @stop

controller:

/* function beingness used in view above */ public function index() { $allvids = video::paginate(10); $allpics = picture::paginate(10); $this->layout->content = \view::make('home.pics_vids_overview', array('allvids' => $allvids, 'allpics' => $allpics)); }

do have add together function/method controller for:

1) accepting input dropdown box user selects 2) passing input newly defined function , displaying results based on match?

if have utilize approach above, function this?

public function pics_vids_categories() { $input = \input::all(); $videos = db::table('videos')->where('category', '=', $input)->get(); $pictures = db::table('pictures')->where('category', '=', $input)->get(); var_dump($videos); var_dump($pictures); }

like said, i'm hoping there's prettier way of doing this.

you may alter index method this:

public function index() { $vdo = video::query(); $pic = picture::query(); if($category = input::get('category')) { $vdo->where('category', $category); $pic->where('category', $category); } $allvids = $vdo->paginate(10); $allpics = $oic->paginate(10); $data = compact('allvids','allpics'); $this->layout->content = \view::make('home.pics_vids_overview', $data); }

now if user selects category , submits form where('category', $category) filter result; otherwise records/models returned.

php laravel-4

No comments:

Post a Comment