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