Support the ongoing development of Laravel.io →
posted 10 years ago
Views Blade

hi

I want to pass the selected item's $id to my controller for doing changing on it .

it's my index.blade.php (view)code:

    <table>
 @foreach($posts as $p)
<tr>
 <td>{{$p->title}}</td>
 <td>{{substr($p->body,0,120).'[...]'}}</td>

  <td>{{HTML::link('posts_show',' Preview',array($p->id))}}</td>
 <td>{{HTML::link('posts_edit','Edit',array($p->id))}}</td>
 <td>
{{Form::open(array('method'=>'DELETE','url'=>array('posts.delete',$p->id)))}}
 {{Form::submit('Delete')}}
 {{Form::close()}}
</td>
</tr>
@endforeach
</table>

it's my route:

    Route::get('post','postController@index');
 Route::get('posts_create',  function (){  return View::make('admin.newPost'); });
 Route::get('posts_show','postController@show');
 Route::get('posts_edit','postController@edit');
 Route::post('posts_delete','postController@destroy');

it's my postController:

class postController extends BaseController{

public function show($id){
    $post=Post::find($id);
    $date=$post->persian_date;
    return View::make('posts.show')->with('post',$post)->with('date',$date);
}

public function edit($id){

    $post=Post::find($id);
    if(is_null($post)){
        return Redirect::route('posts.index');
    }
return View::make('posts.edit')->with('post',$post);
}

public function update($id){
    $input=array_except(Input::all(),'_method');
    Post::find($id)->update($input);
    return Redirect::route('posts.index');

}

public function destroy($id)
{
    Post::find($id)->delete();
    return Redirect::route('posts.index');
}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

prgmsaha prgmsaha Joined 20 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.