basic search capabilities
This commit is contained in:
+14
-12
@@ -2,26 +2,28 @@
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\Portfolio;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Spotlight
|
||||
{
|
||||
public function search(Request $request)
|
||||
{
|
||||
// Do your search logic here
|
||||
// IMPORTANT: apply any security concern here
|
||||
|
||||
if (!auth()->user()) {
|
||||
|
||||
if (!$request->user()) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
return collect([
|
||||
[
|
||||
'name' => 'Mary', // Any string
|
||||
'description' => 'Software Engineer', // Any string
|
||||
'link' => '/users/1', // Any valid route
|
||||
'avatar' => 'http://...' // Any image url
|
||||
]
|
||||
]);
|
||||
$portfolios = Portfolio::where('title', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
|
||||
|
||||
return $portfolios->map(function($portfolio){
|
||||
|
||||
return [
|
||||
'name' => $portfolio->title,
|
||||
'description' => null,
|
||||
'link' => route('portfolio.show', ['portfolio' => $portfolio->id]),
|
||||
'avatar' => null
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user