FEATURE: Add language into widgets
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\WidgetArea;
|
|||||||
use App\Models\WidgetInWidgetArea;
|
use App\Models\WidgetInWidgetArea;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
class AssociateWidget extends Controller
|
class AssociateWidget extends Controller
|
||||||
{
|
{
|
||||||
@@ -18,7 +19,8 @@ class AssociateWidget extends Controller
|
|||||||
{
|
{
|
||||||
$area = WidgetArea::findOrFail($widgetArea);
|
$area = WidgetArea::findOrFail($widgetArea);
|
||||||
$associatedWidgetIds = WidgetInWidgetArea::getWidgetIdsFromArea($area->id);
|
$associatedWidgetIds = WidgetInWidgetArea::getWidgetIdsFromArea($area->id);
|
||||||
$widgets = Widget::paginate(25);
|
$widgets = Widget::where('language', LaravelLocalization::getCurrentLocale())
|
||||||
|
->paginate(25);
|
||||||
|
|
||||||
return view('admin.widgets.association', [
|
return view('admin.widgets.association', [
|
||||||
'widgetArea' => $area,
|
'widgetArea' => $area,
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Models\Widget;
|
use App\Models\Widget;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
class WidgetsOverview extends Controller
|
class WidgetsOverview extends Controller
|
||||||
{
|
{
|
||||||
public function getOverview()
|
public function getOverview()
|
||||||
{
|
{
|
||||||
$widgets = Widget::paginate(25);
|
$widgets = Widget::where('language', LaravelLocalization::getCurrentLocale())
|
||||||
|
->paginate(25);
|
||||||
|
|
||||||
return view('admin.widgets.overview', ['widgets' => $widgets]);
|
return view('admin.widgets.overview', ['widgets' => $widgets]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Widget
|
* Class Widget
|
||||||
@@ -39,6 +40,7 @@ class Widget extends Model
|
|||||||
// create new widget
|
// create new widget
|
||||||
$widget = new Widget();
|
$widget = new Widget();
|
||||||
$widget->widget_type_handler = $widgetType->handler;
|
$widget->widget_type_handler = $widgetType->handler;
|
||||||
|
$widget->language = LaravelLocalization::getCurrentLocale();
|
||||||
$widget->user_id = \Auth::user()->id;
|
$widget->user_id = \Auth::user()->id;
|
||||||
$widget->name = $data->name;
|
$widget->name = $data->name;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WidgetArea
|
* Class WidgetArea
|
||||||
@@ -25,6 +26,7 @@ class WidgetArea extends Model
|
|||||||
->where('code', $uniqueCode)
|
->where('code', $uniqueCode)
|
||||||
->join('widget_in_widget_area', 'widget_in_widget_area.widget_area_id', '=', 'widget_areas.id')
|
->join('widget_in_widget_area', 'widget_in_widget_area.widget_area_id', '=', 'widget_areas.id')
|
||||||
->join('widgets', 'widget_in_widget_area.widget_id', '=', 'widgets.id')
|
->join('widgets', 'widget_in_widget_area.widget_id', '=', 'widgets.id')
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->orderBy('widget_in_widget_area.position');
|
->orderBy('widget_in_widget_area.position');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,12 +8,14 @@ use App\Widgets\Contracts\WidgetRenderer;
|
|||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\Request;
|
use Illuminate\Support\Facades\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
|
||||||
class Menu implements WidgetRenderer
|
class Menu implements WidgetRenderer
|
||||||
{
|
{
|
||||||
protected static function selectContentPages($ids)
|
protected static function selectContentPages($ids)
|
||||||
{
|
{
|
||||||
$pages = Content::where('status', '!=', Content::STATUS_DELETED)
|
$pages = Content::where('status', '!=', Content::STATUS_DELETED)
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
->whereIn('id', $ids)
|
->whereIn('id', $ids)
|
||||||
->get();
|
->get();
|
||||||
$used = [];
|
$used = [];
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddLanguageIntoWidgets extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('widgets', function (Blueprint $table) {
|
||||||
|
$table->string('language', 8)
|
||||||
|
->after('widget_type_handler')
|
||||||
|
->default(\App::getLocale());
|
||||||
|
|
||||||
|
$table->foreign('language')
|
||||||
|
->references('code')
|
||||||
|
->on('languages')
|
||||||
|
->onDelete('cascade')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('widgets', function (Blueprint $table) {
|
||||||
|
$table->dropForeign('widgets_language_foreign');
|
||||||
|
$table->dropColumn('language');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (!empty($widgets))
|
@if (count($widgets))
|
||||||
<table class="full-width">
|
<table class="full-width">
|
||||||
<tr>
|
<tr>
|
||||||
<th>@lang('admin/widgets.widgetType')</th>
|
<th>@lang('admin/widgets.widgetType')</th>
|
||||||
|
|||||||
Reference in New Issue
Block a user