scooby
scooby

Reputation: 207

Laravel 5 - Return array to view

I'm doing a simple search in my view for some registered videos, this search returns the videos searchable through the post on the form.

The problem happens in the return of data, it does not update the page with the array passed to the view.

This is my form:

<form action="{{ URL::to("/search-video") }}" method="POST" accept-charset="utf-8" class="formSend BuscarVideoSend" id="form-busca-video">

    <div class="col l10">

        <input placeholder="Searchvídeo" name="Name" type="text" class="validate input-white Name valid">    
    </div>
    <div class="col l2">
        <button type="submit" class="btnSend" > Search</button> 
    </div>

</form>

Controller:

public function searchVideo(Request $request){
    $data = $request->all();

    $videos = TbVideoModel::where(
        'nm_video', 
        'LIKE', 
        '%'.$data['Name'].'%'
    )->get();


    return view('layouts.videos', compact('videos', $videos));
}

Html to return:

<section id="videoMosaic">
    <div class="row "> 
        <ul>

            @if(isset($videos))
                @foreach($videos as $video)
                <li>
                    <a class="bla-1" href="{{$video->ds_link}}">
                        <div class="div-imagem-texto">
                            <img src="http://img.youtube.com/vi/{{$video['ds_imagem_video']}}/0.jpg" alt="">
                            <div class="texto-sobre-imagem">
                                <img src="/images/play.png" alt="" class="play">
                                {{$video->nm_video}}
                                <p>{{$video->tx_video}}</p>

                            </div>                        
                        </div>
                    </a> 
                </li>
                @endforeach
            @endif
        </ul>

    </div>
</section>

It returns the data correctly on console xhr, but it has this error:

Uncaught SyntaxError: Unexpected token <

What do I need for the page to be updated with search data? Tks

Upvotes: 1

Views: 1185

Answers (1)

Dov Benyomin Sohacheski
Dov Benyomin Sohacheski

Reputation: 7714

There error is in your compact function:

return view('layouts.videos', compact('videos'));

PHP Docs on compact()

Upvotes: 1

Related Questions