为什么不在Laravel 5.6应用程序中使用最新方法



使用laravel 5.6,在我的应用程序中,我使用算法在index blade中搜索输入。index.blade.php

<form method="GET" action="{{ url('search') }}">
{{csrf_field()}}
<div class="row">
<div class="col-md-6">
<input type="text" name="search" class="form-control" placeholder="Search">
</div>
<div class="col-md-6">
<button class="btn btn-info">Search</button>
</div>
</div>
</form>
<br> 
@forelse( $vehicles as $vehicule )

@if( $vehicule->uploads->count() > 0 )
<a href="{{ route('vehicles.show', $vehicule->id) }}">
@php
$upload = $vehicule->uploads->sortByDesc('id')->first();
@endphp
<div style="border-style: solid; background-color: {{ $vehicule->adtype === 1 ? '#FFEFD5' : '#FFFFFF' }} ">
<img src="/images/{{ $upload->resized_name }}" height="150" width="250"></a>

{{ CarbonCarbon::parse($vehicule->created_at)->diffForHumans()}} 
{{$vehicule->provincename}}
{{$vehicule->milage}}
</div>
<br>
<hr>
@endif
@empty
<td>No Advertisment to display.</td>
@endforelse
</div>
</div>
</div>
{{ $vehicles->links() }}
</div>
@endsection

我已经用索引刀片文件设置了分页。

这是SearchController@search作用

public function search(Request $request)
{
$vehicles =  Vehicle::search($request->get('search'))->orderBy('adtype','DESC')
->latest('updated_at')
->paginate(10);
return view('vehicles.index', compact('vehicles'));
} 

但是当我在搜索输入中输入一些值并输入搜索按钮时

following error is occurred.
1/1) BadMethodCallException
Method latest does not exist.

如何解决这个问题?

编辑dd结果

Builder {#375 ▼
+model: Vehicle {#372 ▶}
+query: "gampaha"
+callback: null
+index: null
+wheres: []
+limit: null
+orders: array:1 [▶]
}

更新的车型

use Searchable;
protected $guarded = [];
public function searchableAs()
{
return 'categoryname';
}

试试这个,告诉你会得到什么

Vehicle::where('column1', 'like', '%' . $request->get('search') . '%')->orWhere('column2', 'like', '%' . $request->get('search') . '%')->orderBy('adtype', 'DESC')   ->latest('updated_at')   ->paginate(10);

并在您的车型中分享您的搜索方法。

最新更新