-
Notifications
You must be signed in to change notification settings - Fork 31
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
1 parent
9cbeda6
commit 2cbba5b
Showing
237 changed files
with
14,012 additions
and
6,693 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class RefreshDatabase extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'refresh:database'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
if(ENV('IS_DEMO')){ | ||
|
||
\Artisan::call('migrate:fresh --seed'); | ||
} | ||
} | ||
} |
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,129 @@ | ||
<?php | ||
|
||
namespace App\DataTables; | ||
|
||
use App\Models\User; | ||
use Yajra\DataTables\Html\Button; | ||
use Yajra\DataTables\Html\Column; | ||
use Yajra\DataTables\Services\DataTable; | ||
|
||
class UsersDataTable extends DataTable | ||
{ | ||
/** | ||
* Build DataTable class. | ||
* | ||
* @param mixed $query Results from query() method. | ||
* @return \Yajra\DataTables\DataTableAbstract | ||
*/ | ||
public function dataTable($query) | ||
{ | ||
return datatables() | ||
->eloquent($query) | ||
->editColumn('userProfile.country', function($query) { | ||
return $query->userProfile->country ?? '-'; | ||
}) | ||
->editColumn('userProfile.company_name', function($query) { | ||
return $query->userProfile->company_name ?? '-'; | ||
}) | ||
->editColumn('status', function($query) { | ||
$status = 'warning'; | ||
switch ($query->status) { | ||
case 'active': | ||
$status = 'primary'; | ||
break; | ||
case 'inactive': | ||
$status = 'danger'; | ||
break; | ||
case 'banned': | ||
$status = 'dark'; | ||
break; | ||
} | ||
return '<span class="text-capitalize badge bg-'.$status.'">'.$query->status.'</span>'; | ||
}) | ||
->editColumn('created_at', function($query) { | ||
return date('Y/m/d',strtotime($query->created_at)); | ||
}) | ||
->filterColumn('full_name', function($query, $keyword) { | ||
$sql = "CONCAT(users.first_name,' ',users.last_name) like ?"; | ||
return $query->whereRaw($sql, ["%{$keyword}%"]); | ||
}) | ||
->filterColumn('userProfile.company_name', function($query, $keyword) { | ||
return $query->orWhereHas('userProfile', function($q) use($keyword) { | ||
$q->where('company_name', 'like', "%{$keyword}%"); | ||
}); | ||
}) | ||
->filterColumn('userProfile.country', function($query, $keyword) { | ||
return $query->orWhereHas('userProfile', function($q) use($keyword) { | ||
$q->where('country', 'like', "%{$keyword}%"); | ||
}); | ||
}) | ||
->addColumn('action', 'users.action') | ||
->rawColumns(['action','status']); | ||
} | ||
|
||
/** | ||
* Get query source of dataTable. | ||
* | ||
* @param \App\Models\User $model | ||
* @return \Illuminate\Database\Eloquent\Builder | ||
*/ | ||
public function query() | ||
{ | ||
$model = User::query()->with('userProfile'); | ||
return $this->applyScopes($model); | ||
} | ||
|
||
/** | ||
* Optional method if you want to use html builder. | ||
* | ||
* @return \Yajra\DataTables\Html\Builder | ||
*/ | ||
public function html() | ||
{ | ||
return $this->builder() | ||
->setTableId('dataTable') | ||
->columns($this->getColumns()) | ||
->minifiedAjax() | ||
->dom('<"row align-items-center"<"col-md-2" l><"col-md-6" B><"col-md-4"f>><"table-responsive my-3" rt><"row align-items-center" <"col-md-6" i><"col-md-6" p>><"clear">') | ||
|
||
->parameters([ | ||
"processing" => true, | ||
"autoWidth" => false, | ||
]); | ||
} | ||
|
||
/** | ||
* Get columns. | ||
* | ||
* @return array | ||
*/ | ||
protected function getColumns() | ||
{ | ||
return [ | ||
['data' => 'id', 'name' => 'id', 'title' => 'id'], | ||
['data' => 'full_name', 'name' => 'full_name', 'title' => 'FULL NAME', 'orderable' => false], | ||
['data' => 'phone_number', 'name' => 'phone_number', 'title' => 'Phone Number'], | ||
['data' => 'email', 'name' => 'email', 'title' => 'Email'], | ||
['data' => 'userProfile.country', 'name' => 'userProfile.country', 'title' => 'Country'], | ||
['data' => 'status', 'name' => 'status', 'title' => 'Status'], | ||
['data' => 'userProfile.company_name', 'name' => 'userProfile.company_name', 'title' => 'Company'], | ||
['data' => 'created_at', 'name' => 'created_at', 'title' => 'Join Date'], | ||
Column::computed('action') | ||
->exportable(false) | ||
->printable(false) | ||
->searchable(false) | ||
->width(60) | ||
->addClass('text-center hide-search'), | ||
]; | ||
} | ||
|
||
/** | ||
* Get filename for export. | ||
* | ||
* @return string | ||
*/ | ||
protected function filename() | ||
{ | ||
return 'Users_' . date('YmdHis'); | ||
} | ||
} |
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,67 @@ | ||
<?php | ||
|
||
namespace App\Helpers; | ||
|
||
use Exception; | ||
use Illuminate\Support\Facades\Session; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class AuthHelper { | ||
public static function authSession(){ | ||
$session = new \App\Models\User; | ||
if(Session::has('auth_user')){ | ||
$session = Session::get('auth_user'); | ||
}else{ | ||
$user = Auth::user(); | ||
Session::put('auth_user',$user); | ||
$session = Session::get('auth_user'); | ||
} | ||
return $session; | ||
} | ||
|
||
public static function checkMenuRoleAndPermission($menu) | ||
{ | ||
if (Auth::check()) { | ||
if ($menu->data('role') == null && auth()->user()->hasRole('admin')) { | ||
return true; | ||
} | ||
|
||
if($menu->data('permission') == null && $menu->data('role') == null) { | ||
return true; | ||
} | ||
|
||
if($menu->data('role') != null) { | ||
if(auth()->user()->hasAnyRole(explode(',', $menu->data('role')))) { | ||
return true; | ||
} | ||
} | ||
|
||
if($menu->data('permission') != null) { | ||
if(auth()->user()->can($menu->data('permission')) ) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static function checkRolePermission($role,$permission){ | ||
try{ | ||
if($role->hasPermissionTo($permission)){ | ||
return true; | ||
} | ||
return false; | ||
}catch (Exception $e){ | ||
return false; | ||
} | ||
} | ||
|
||
public static function demoUserPermission(){ | ||
if(Auth::user()->hasRole('demo_admin')){ | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.