Added Suggestion module on pages
This commit is contained in:
48
app/Http/ViewComposers/Suggestions.php
Normal file
48
app/Http/ViewComposers/Suggestions.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\ViewComposers;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use App\Traits\Modules;
|
||||
use Route;
|
||||
use Module;
|
||||
|
||||
class Suggestions
|
||||
{
|
||||
use Modules;
|
||||
|
||||
/**
|
||||
* Bind data to the view.
|
||||
*
|
||||
* @param View $view
|
||||
* @return void
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$suggestion_module = false;
|
||||
|
||||
$path = Route::current()->uri();
|
||||
|
||||
if ($path) {
|
||||
$suggestions = $this->getSuggestions($path);
|
||||
|
||||
if ($suggestions) {
|
||||
$suggestion_modules = $suggestions->modules;
|
||||
|
||||
foreach ($suggestion_modules as $key => $module) {
|
||||
if (Module::findByAlias($module->alias)) {
|
||||
unset($suggestion_modules[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($suggestion_modules) {
|
||||
shuffle($suggestion_modules);
|
||||
|
||||
$suggestion_module[] = $suggestion_modules[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$view->with(['suggestion_modules' => $suggestion_module]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user