forked from rapidez/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robin Mulder
committed
Oct 11, 2023
1 parent
eeae34b
commit ad2babd
Showing
4 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Str; | ||
|
||
class SearchController | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$searchQuery = config('rapidez.models.search_query')::firstOrNew([ | ||
'query_text' => Str::lower($request->q), | ||
'store_id' => config('rapidez.store'), | ||
], ['popularity' => 1]); | ||
|
||
if (! $searchQuery->exists) { | ||
$searchQuery->save(); | ||
|
||
return view('rapidez::search.overview'); | ||
} | ||
|
||
$searchQuery->increment('popularity'); | ||
|
||
if ($searchQuery->is_active === 1 && $searchQuery->redirect) { | ||
return redirect($searchQuery->redirect, 301); | ||
} | ||
|
||
return view('rapidez::search.overview'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class SearchQuery extends Model | ||
{ | ||
const CREATED_AT = null; | ||
|
||
protected $table = 'search_query'; | ||
|
||
protected $primaryKey = 'query_id'; | ||
|
||
protected $guarded = []; | ||
} |