a056f8dd3913f4dd0869e1f55450ecd4第6行中的Laravel 5 FatalErrorException:语法错误,意外':',期待'(''

时间:2015-09-27 18:29:48

标签: php laravel-5

我正在按照教程进行用户搜索。我可以让脚本显示原始数据,但是当我使用时:

return view('search.results')->with('users', $users);

我得到了FatalError异常

继承我的搜索控制器:     

namespace Aries\Http\Controllers;

use DB;
use Aries\Models\User;
use Illuminate\Http\Request;

class SearchController extends Controller
{
    public function getResults(Request $request)
    {
        $query = $request->input('query');

        if(!$query) {
            return redirect()->route('home');
        }

        $users = User::where(DB::raw("CONCAT(first_name, ' ', last_name)"), 'LIKE', "%{$query}%")->orWhere('username', 'LIKE', "%{$query}%")->get();

        return view('search.results')->with('users', $users);
    }
}

搜索/ results.blade.php

@extends('templates.default')

@section('content')
    <h3>Your search for "{{ Request::input('query') }}"</h3>

    @if (!$users->count())
        <p>No results found, sorry.</p>
    @elseif
        <div class="row">
        <div class="col-lg-12">
            @foreach ($users as $user)
                @include('user/partials/userblock')
            @endforeach
        </div>
    </div>
@stop

用户/ userblock.blade.php

<div class="media">
    <a class="pull-left" href="#">
        <img class="media-object" alt="" src="">
    </a>
    <div class="media-body">
        <h4 class="media-heading"><a href="#">{{ $user->getNameOrUsername() }}</a></h4>
    @if ($user->location)
        <p>{{ $user->location }}</p>
    @endif
    </div>
</div>

我已查看了所有内容,但我无法找到问题,当我注释掉返回视图()时工作正常;

1 个答案:

答案 0 :(得分:0)

@if (!$users->count())
    <p>No results found, sorry.</p>
@elseif

elseif期待在那里发布第二个条件语句。使用@else或添加条件。