Mohammad
Mohammad

Reputation: 85

retrieve data after search :: laravel

i have problem when i want to retrieve my data

first i get data from view and after send it to controller like this :

view :

            {{ Form::open() }}
                {{ Form::label('Title : ') }}
                {{ Form::text('Search') }}
                {{ Form::submit('Search') }}
            {{ Form::close() }}

route :

Route::get('search', function () {
    return view('search');
});

Route::post('search', 'SearchController@Search');

controller :

public function Search () {

    $SearchText = Input::get('Search');

    return Posts::where('Title', 'LIKE', '%'.$SearchText.'%')->get();

}

now i want to return th columns of table that i searched.

i try " Posts->ID , Posts->Description " but it is wrong......

Upvotes: 2

Views: 491

Answers (1)

Prince Lionel N'zi
Prince Lionel N'zi

Reputation: 2588

The code below will give you a group of posts

Posts::where('Title', 'LIKE', '%'.$SearchText.'%')->get();

So to get the id and the description, you can do this in your blade template:

@foreach($posts as $post)
    {{ $post->id }} <br>
    {{ $post->description }}
@endforeach

In you PHP code, you can do:

foreach($posts as $post) {

  $postId = $post->id;
  $postDescription = $post->description;

}

Upvotes: 1

Related Questions