Commit 7f79ef73 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/Core/' changes from e713728..5720517

5720517 Add a find by slug method
2e9ab39 Add an allTranslatedIn method
973bfae Add the current locale to every view
a6c0327 Remove the construct dependency injection

git-subtree-dir: Modules/Core
git-subtree-split: 5720517463d1476dda7586817040132bf14f14ed
parent 3f527cd4
<?php namespace Modules\Core\Composers;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\App;
class LocaleComposer
{
public function compose(View $view)
{
$view->with('currentLocale', App::getLocale());
}
}
......@@ -13,9 +13,9 @@ abstract class BasePublicController
*/
private $setting;
public function __construct(Setting $setting)
public function __construct()
{
$this->setting = $setting;
$this->setting = app('setting.settings');
$this->theme = $this->setting->get('core::template');
}
}
......@@ -39,4 +39,18 @@ interface BaseRepository
* @return mixed
*/
public function destroy($model);
/**
* Return resources translated in the given language
* @param $lang
* @return object
*/
public function allTranslatedIn($lang);
/**
* Find a resource by the given slug
* @param int $slug
* @return object
*/
public function findBySlug($slug);
}
......@@ -60,4 +60,30 @@ abstract class EloquentBaseRepository implements BaseRepository
{
return $model->delete();
}
/**
* Return all categories in the given language
* @param $lang
* @return mixed
*/
public function allTranslatedIn($lang)
{
return $this->model->whereHas('translations', function($q) use($lang)
{
$q->where('locale', "$lang");
})->orderBy('created_at', 'DESC')->get();
}
/**
* Find a resource by the given slug
* @param int $slug
* @return object
*/
public function findBySlug($slug)
{
return $this->model->whereHas('translations', function($q) use($slug)
{
$q->where('slug', "$slug");
})->first();
}
}
......@@ -3,3 +3,4 @@
View::creator('core::partials.sidebar-nav', 'Modules\Core\Composers\SidebarViewCreator');
View::composer('core::layouts.master', 'Modules\Core\Composers\MasterViewComposer');
View::composer('core::fields.select-theme', 'Modules\Core\Composers\ThemeComposer');
View::composer('*', 'Modules\Core\Composers\LocaleComposer');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment