Created
August 30, 2018 07:15
-
-
Save vanbaodo/92c334aeb817c88e1593d00baa5fbcdf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace App\Console; | |
use Illuminate\Console\Scheduling\Schedule; | |
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | |
class Kernel extends ConsoleKernel | |
{ | |
/** | |
* The Artisan commands provided by your application. | |
* | |
* @var array | |
*/ | |
protected $commands = [ | |
// | |
]; | |
/** | |
* Define the application's command schedule. | |
* | |
* @param \Illuminate\Console\Scheduling\Schedule $schedule | |
* @return void | |
*/ | |
protected function schedule(Schedule $schedule) | |
{ | |
// $schedule->command('inspire') | |
// ->hourly(); | |
} | |
/** | |
* Register the commands for the application. | |
* | |
* @return void | |
*/ | |
protected function commands() | |
{ | |
$this->load(__DIR__.'/Commands'); | |
require base_path('routes/console.php'); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Exceptions; | |
use Exception; | |
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | |
class Handler extends ExceptionHandler | |
{ | |
/** | |
* A list of the exception types that are not reported. | |
* | |
* @var array | |
*/ | |
protected $dontReport = [ | |
// | |
]; | |
/** | |
* A list of the inputs that are never flashed for validation exceptions. | |
* | |
* @var array | |
*/ | |
protected $dontFlash = [ | |
'password', | |
'password_confirmation', | |
]; | |
/** | |
* Report or log an exception. | |
* | |
* @param \Exception $exception | |
* @return void | |
*/ | |
public function report(Exception $exception) | |
{ | |
parent::report($exception); | |
} | |
/** | |
* Render an exception into an HTTP response. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Exception $exception | |
* @return \Illuminate\Http\Response | |
*/ | |
public function render($request, Exception $exception) | |
{ | |
return parent::render($request, $exception); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Helpers; | |
class Helpers { | |
/* | |
* Check exit email | |
*/ | |
public static function checkUsernameOrEmail($str) { | |
$check_is_email = strpos($str,'@'); | |
if (isset($check_is_email)) return true; | |
return false; | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Helpers; | |
use Illuminate\Support\Facades\Storage; | |
use Illuminate\Http\File; | |
use Illuminate\Http\UploadedFile; | |
class UploadsHelper { | |
public static function getFileExtension($name, $request) { | |
if ($request->hasFile($name)) { | |
$image = $request->file($name); | |
return $image->getClientOriginalExtension(); | |
} | |
return ''; | |
} | |
public static function uploadFileOrigin($image, $uploadPath, $name , $request , $userId) { | |
if ($request->hasFile($name)) { | |
$imageName = $image->getClientOriginalName(); | |
$file_extension = self::getFileExtension($name, $request); | |
return $file_extension; | |
if (!is_dir($uploadPath)) { | |
mkdir($uploadPath, 0777, true); | |
} | |
$image->move($uploadPath, $imageName); | |
return '/' . $uploadPath . '/' . $imageName; | |
} | |
} | |
public static function getOriginImage($name, $dir, $request, $userId) { | |
if ($request->hasFile($name)) { | |
$image = $request->file($name); | |
// Upload file | |
$uploadPath = str_replace('USERID', $userId, $dir); | |
$image = self::uploadFileOrigin($image, $uploadPath , $name , $request , $userId); | |
return $image; | |
} | |
return ''; | |
} | |
public static function uploadAvatar($name , $uploadPath , $request , $userId) { | |
if ($request->hasFile($name)) { | |
$image = $request->file($name); | |
$imageSize = $image->getSize(); | |
$maxSize = ceil(($imageSize/1024)/1024); | |
if ($maxSize>5) { | |
return false; | |
} else { | |
if (!is_dir($uploadPath)) { | |
mkdir($uploadPath, 0777, true); | |
} | |
$extension_file = $image->getClientOriginalExtension(); | |
$imageName = $image->getClientOriginalName(); | |
$newName = 'driver'.$userId.'.'.$extension_file; | |
$image->move($uploadPath, $newName); | |
return '/' . $uploadPath . '/' . $newName; | |
} | |
} | |
return ''; | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; | |
class ForgotPasswordController extends Controller | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Password Reset Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller is responsible for handling password reset emails and | |
| includes a trait which assists in sending these notifications from | |
| your application to your users. Feel free to explore this trait. | |
| | |
*/ | |
use SendsPasswordResetEmails; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest'); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
class LoginController extends Controller | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Login Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller handles authenticating users for the application and | |
| redirecting them to your home screen. The controller uses a trait | |
| to conveniently provide its functionality to your applications. | |
| | |
*/ | |
use AuthenticatesUsers; | |
/** | |
* Where to redirect users after login. | |
* | |
* @var string | |
*/ | |
protected $redirectTo = '/home'; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest')->except('logout'); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\User; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Support\Facades\Hash; | |
use Illuminate\Support\Facades\Validator; | |
use Illuminate\Foundation\Auth\RegistersUsers; | |
class RegisterController extends Controller | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Register Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller handles the registration of new users as well as their | |
| validation and creation. By default this controller uses a trait to | |
| provide this functionality without requiring any additional code. | |
| | |
*/ | |
use RegistersUsers; | |
/** | |
* Where to redirect users after registration. | |
* | |
* @var string | |
*/ | |
protected $redirectTo = '/home'; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest'); | |
} | |
/** | |
* Get a validator for an incoming registration request. | |
* | |
* @param array $data | |
* @return \Illuminate\Contracts\Validation\Validator | |
*/ | |
protected function validator(array $data) | |
{ | |
return Validator::make($data, [ | |
'name' => 'required|string|max:255', | |
'email' => 'required|string|email|max:255|unique:users', | |
'password' => 'required|string|min:6|confirmed', | |
]); | |
} | |
/** | |
* Create a new user instance after a valid registration. | |
* | |
* @param array $data | |
* @return \App\User | |
*/ | |
protected function create(array $data) | |
{ | |
return User::create([ | |
'name' => $data['name'], | |
'email' => $data['email'], | |
'password' => Hash::make($data['password']), | |
]); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\ResetsPasswords; | |
class ResetPasswordController extends Controller | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Password Reset Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller is responsible for handling password reset requests | |
| and uses a simple trait to include this behavior. You're free to | |
| explore this trait and override any methods you wish to tweak. | |
| | |
*/ | |
use ResetsPasswords; | |
/** | |
* Where to redirect users after resetting their password. | |
* | |
* @var string | |
*/ | |
protected $redirectTo = '/home'; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest'); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Foundation\Bus\DispatchesJobs; | |
use Illuminate\Routing\Controller as BaseController; | |
use Illuminate\Foundation\Validation\ValidatesRequests; | |
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; | |
class Controller extends BaseController | |
{ | |
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; | |
protected function renderJsonResponse($data = [], $msg = '', $code = 0) { | |
$response = array(); | |
$response['response_status'] = $code; | |
$response['response_msg'] = $msg; | |
$response['response_content'] = $data; | |
return response()->json($response); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http; | |
use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
class Kernel extends HttpKernel | |
{ | |
/** | |
* The application's global HTTP middleware stack. | |
* | |
* These middleware are run during every request to your application. | |
* | |
* @var array | |
*/ | |
protected $middleware = [ | |
\App\Http\Middleware\CheckForMaintenanceMode::class, | |
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, | |
\App\Http\Middleware\TrimStrings::class, | |
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, | |
\App\Http\Middleware\TrustProxies::class, | |
]; | |
/** | |
* The application's route middleware groups. | |
* | |
* @var array | |
*/ | |
protected $middlewareGroups = [ | |
'web' => [ | |
\App\Http\Middleware\EncryptCookies::class, | |
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, | |
\Illuminate\Session\Middleware\StartSession::class, | |
// \Illuminate\Session\Middleware\AuthenticateSession::class, | |
\Illuminate\View\Middleware\ShareErrorsFromSession::class, | |
\App\Http\Middleware\VerifyCsrfToken::class, | |
\Illuminate\Routing\Middleware\SubstituteBindings::class, | |
], | |
'api' => [ | |
'throttle:60,1', | |
'bindings', | |
], | |
]; | |
/** | |
* The application's route middleware. | |
* | |
* These middleware may be assigned to groups or used individually. | |
* | |
* @var array | |
*/ | |
protected $routeMiddleware = [ | |
'auth' => \Illuminate\Auth\Middleware\Authenticate::class, | |
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, | |
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, | |
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, | |
'can' => \Illuminate\Auth\Middleware\Authorize::class, | |
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, | |
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, | |
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, | |
]; | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Middleware; | |
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware; | |
class CheckForMaintenanceMode extends Middleware | |
{ | |
/** | |
* The URIs that should be reachable while maintenance mode is enabled. | |
* | |
* @var array | |
*/ | |
protected $except = [ | |
// | |
]; | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Facades\Auth; | |
class RedirectIfAuthenticated | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @param string|null $guard | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next, $guard = null) | |
{ | |
if (Auth::guard($guard)->check()) { | |
return redirect('/home'); | |
} | |
return $next($request); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Middleware; | |
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware; | |
class TrimStrings extends Middleware | |
{ | |
/** | |
* The names of the attributes that should not be trimmed. | |
* | |
* @var array | |
*/ | |
protected $except = [ | |
'password', | |
'password_confirmation', | |
]; | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Middleware; | |
use Illuminate\Http\Request; | |
use Fideloper\Proxy\TrustProxies as Middleware; | |
class TrustProxies extends Middleware | |
{ | |
/** | |
* The trusted proxies for this application. | |
* | |
* @var array | |
*/ | |
protected $proxies; | |
/** | |
* The headers that should be used to detect proxies. | |
* | |
* @var int | |
*/ | |
protected $headers = Request::HEADER_X_FORWARDED_ALL; | |
} |
This file contains hidden or 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
<?php | |
namespace App\Http\Middleware; | |
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware; | |
class VerifyCsrfToken extends Middleware | |
{ | |
/** | |
* The URIs that should be excluded from CSRF verification. | |
* | |
* @var array | |
*/ | |
protected $except = [ | |
// | |
]; | |
} |
This file contains hidden or 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
<?php | |
namespace App\Models; | |
use Illuminate\Notifications\Notifiable; | |
use Illuminate\Foundation\Auth\User as Authenticatable; | |
class Users extends Authenticatable | |
{ | |
use Notifiable; | |
/** | |
* The attributes that are mass assignable. | |
* | |
* @var array | |
*/ | |
protected $fillable = [ | |
'name', 'email', 'password', | |
]; | |
/** | |
* The attributes that should be hidden for arrays. | |
* | |
* @var array | |
*/ | |
protected $hidden = [ | |
'password', 'remember_token', | |
]; | |
} |
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\Facades\Gate; | |
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | |
class AuthServiceProvider extends ServiceProvider | |
{ | |
/** | |
* The policy mappings for the application. | |
* | |
* @var array | |
*/ | |
protected $policies = [ | |
'App\Model' => 'App\Policies\ModelPolicy', | |
]; | |
/** | |
* Register any authentication / authorization services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
$this->registerPolicies(); | |
// | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use Illuminate\Support\Facades\Broadcast; | |
class BroadcastServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Broadcast::routes(); | |
require base_path('routes/channels.php'); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\Facades\Event; | |
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | |
class EventServiceProvider extends ServiceProvider | |
{ | |
/** | |
* The event listener mappings for the application. | |
* | |
* @var array | |
*/ | |
protected $listen = [ | |
'App\Events\Event' => [ | |
'App\Listeners\EventListener', | |
], | |
]; | |
/** | |
* Register any events for your application. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
parent::boot(); | |
// | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
class HelpersServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap the application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// | |
} | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
require_once app_path() . '/Helpers/Helpers.php'; | |
require_once app_path() . '/Helpers/UploadsHelper.php'; | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
class RepositoryServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap the application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// | |
} | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$models = array( | |
'Posts', | |
'Drivers', | |
'Users', | |
'DriverBookOptions', | |
'UserPosts', | |
'DriverCars', | |
'DriverPosts', | |
'UserBooks', | |
'Cars', | |
'Cities', | |
'DriverBooks', | |
'Searches' | |
); | |
foreach ($models as $idx => $model) { | |
$this->app->bind("App\Repositories\\{$model}Repository", | |
"App\Repositories\Eloquent\\{$model}RepositoryEloquent"); | |
} | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\Facades\Route; | |
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; | |
class RouteServiceProvider extends ServiceProvider | |
{ | |
/** | |
* This namespace is applied to your controller routes. | |
* | |
* In addition, it is set as the URL generator's root namespace. | |
* | |
* @var string | |
*/ | |
protected $namespace = 'App\Http\Controllers'; | |
/** | |
* Define your route model bindings, pattern filters, etc. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// | |
parent::boot(); | |
} | |
/** | |
* Define the routes for the application. | |
* | |
* @return void | |
*/ | |
public function map() | |
{ | |
$this->mapApiRoutes(); | |
$this->mapWebRoutes(); | |
// | |
} | |
/** | |
* Define the "web" routes for the application. | |
* | |
* These routes all receive session state, CSRF protection, etc. | |
* | |
* @return void | |
*/ | |
protected function mapWebRoutes() | |
{ | |
Route::middleware('web') | |
->namespace($this->namespace) | |
->group(base_path('routes/web.php')); | |
} | |
/** | |
* Define the "api" routes for the application. | |
* | |
* These routes are typically stateless. | |
* | |
* @return void | |
*/ | |
protected function mapApiRoutes() | |
{ | |
Route::prefix('api') | |
->middleware('api') | |
->namespace($this->namespace) | |
->group(base_path('routes/api.php')); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Repositories; | |
use Illuminate\Support\Facades\DB; | |
use App\Repositories\RepositoryInterface; | |
abstract class BaseRepository implements RepositoryInterface { | |
/** | |
* @var $model | |
*/ | |
protected $model; | |
abstract public function model(); | |
public function makeModel() | |
{ | |
$model = $this->app->make($this->model()); | |
if (!$model instanceof Model) { | |
throw new RepositoryException("Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model"); | |
} | |
return $this->model = $model; | |
} | |
/** | |
* @param int $id | |
* @return mixed | |
*/ | |
public function getById($id) | |
{ | |
return $this->model->findOrFail($id); | |
} | |
/** | |
* @param array $columns | |
* @return mixed | |
*/ | |
public function all($orderBy = 'updated_at desc',$columns = array('*')) | |
{ | |
return $this->model->orderByRaw($orderBy)->get($columns); | |
} | |
/** | |
* @param int $perPage Per page | |
* @param array $columns Array Columns | |
* @return array Return data paginate | |
*/ | |
public function paginate($perPage = 15, $columns = array('*')) | |
{ | |
return $this->model->paginate($perPage, $columns); | |
} | |
/** | |
* @param array $data Array data | |
* @return void | |
*/ | |
public function create(array $data) | |
{ | |
return $this->model->create($data); | |
} | |
/** | |
* @param array $data Array data | |
* @param $id ID | |
* @param string $attribute Attribute | |
* @return void | |
*/ | |
public function update(array $data, $id, $attribute = "id") | |
{ | |
return $this->model->where($attribute, '=', $id)->update($data); | |
} | |
/** | |
* @param $id ID | |
* @return void | |
*/ | |
public function delete($id) | |
{ | |
return $this->model->destroy($id); | |
} | |
/** | |
* @param $id ID | |
* @param array $columns Columns | |
* @return array Return array | |
*/ | |
public function find($id, $columns = array('*')) | |
{ | |
return $this->model->find($id, $columns); | |
} | |
/** | |
* @param $attribute Attribute | |
* @param $value Value | |
* @param array $columns Columns | |
* @return array Array | |
*/ | |
public function findBy($attribute, $value, $columns = array('*')) | |
{ | |
return $this->model->where($attribute, '=', $value)->first($columns); | |
} | |
public function findByReturnArray($attribute, $value, $columns = array('*')) | |
{ | |
return $this->model->where($attribute, '=', $value)->get($columns); | |
} | |
public function findByReturnArrayPlug($attribute, $value, $pluck, $columns = array('*') ) | |
{ | |
return $this->model->where($attribute, '=', $value)->get($columns)->pluck($pluck); | |
} | |
public function findByMultiConditionsLimit($whereData = array(), $columns = array('*')) | |
{ | |
return $this->model->where($whereData)->first($columns); | |
} | |
/** | |
* @param $tableName Table name | |
* @param array $whereData Array where data | |
* @return array Return array | |
*/ | |
public function findByMultiConditions($tableName, $whereData = array()) | |
{ | |
return DB::table($tableName)->where($whereData)->get(); | |
} | |
/** | |
* @param $tableName Table name | |
* @param array $whereData Array where data | |
* @return array Return array | |
*/ | |
public function pagingWithMultiConditions($tableName, $whereData = array(), $perPage = 15, $orderBy = 'id desc', $columns = array('*')) | |
{ | |
return DB::table($tableName) | |
->where($whereData) | |
->orderByRaw($orderBy) | |
->paginate($perPage, $columns); | |
} | |
public function delByMultiConditions($tableName, $whereData = array()) | |
{ | |
return DB::table($tableName) | |
->where($whereData) | |
->delete(); | |
} | |
/** | |
* @param array $whereData | |
* @return mixed | |
*/ | |
public function delByMultiConditionsModel($whereData = array()) | |
{ | |
return $this->model | |
->where($whereData) | |
->delete(); | |
} | |
/** | |
* update records by multi conditions | |
* | |
* @param $tableName Table name | |
* @param array $data Array data | |
* @param array $whereData Array where data | |
* @return void | |
*/ | |
public function updateByMultiConditionsModel(array $data, $whereData = array()) | |
{ | |
return $this->model | |
->where($whereData) | |
->update($data); | |
} | |
/** | |
* @param $tableName | |
* @param array $whereData | |
* @return mixed | |
*/ | |
public function countByMultiConditions($tableName, $whereData = array()) | |
{ | |
return DB::table($tableName) | |
->where($whereData) | |
->count(); | |
} | |
/** | |
* @param array $whereData | |
* @return mixed | |
*/ | |
public function countByMultiConditionsModel($whereData = array()) | |
{ | |
return $this->model | |
->where($whereData) | |
->count(); | |
} | |
/** | |
* @param array $whereData | |
* @param string $orderBy | |
* @param array $select | |
* @return mixed | |
*/ | |
public function getByMultiConditionsModel($whereData = array(), $orderBy = "id desc", $select=array("*") ) { | |
return $this->model | |
->select($select) | |
->where($whereData) | |
->orderByRaw($orderBy) | |
->get(); | |
} | |
public function getByMultiConditionsPagination($tableName, $whereData = array(), $select=array("*") , $orderBy = "id desc", $perpage = 10) { | |
return DB::table($tableName) | |
->select($select) | |
->where($whereData) | |
->orderByRaw($orderBy) | |
->paginate($perpage); | |
} | |
public function getByInConditions($tableName, $field, $data = array(), $select = array("*"), $orderBy = "id desc"){ | |
return DB::table($tableName) | |
->select($select) | |
->whereIn($field, $data) | |
->orderByRaw($orderBy) | |
->get(); | |
} | |
public function getManyWhereOrder($whereData = array(), $select=array("*"), $orderBy = "id asc") | |
{ | |
return $this->model | |
->where($whereData) | |
->select($select) | |
->orderByRaw($orderBy) | |
->get(); | |
} | |
public function getManyWhereOrderLimitNumber($whereData = array(), $limit = 5, $select=array("*"), $orderBy = "id desc") | |
{ | |
return $this->model | |
->where($whereData) | |
->select($select) | |
->orderByRaw($orderBy) | |
->limit($limit) | |
->get(); | |
} | |
public function getManyWhereOrderLimit($whereData = array(), $select=array("*"), $orderBy = "id desc") | |
{ | |
return $this->model | |
->where($whereData) | |
->select($select) | |
->orderByRaw($orderBy) | |
->first(); | |
} | |
public function getManyWhereOrderPagination($whereData = array(), $select=array("*"), $orderBy = "id desc", $perpage = 10) | |
{ | |
return $this->model | |
->where($whereData) | |
->select($select) | |
->orderByRaw($orderBy) | |
->paginate($perpage); | |
} | |
public function searchItemInStringList($stringList, $columnSearch, $select=array("*")) | |
{ | |
return $this->model | |
->select($select) | |
->whereRaw("find_in_set(" . $columnSearch . ", '" . $stringList . "')") | |
->get(); | |
} | |
public function searchItemInStringListUnequi($stringList, $columnSearch, $select=array("*"), $whereData = array()) | |
{ | |
return $this->model | |
->select($select) | |
->distinct() | |
->where($whereData) | |
->whereRaw("find_in_set(" . $columnSearch . ", '" . $stringList . "')") | |
->get(); | |
} | |
public function deleteByMultiConditions($whereData = array()) | |
{ | |
return $this->model | |
->where($whereData) | |
->delete(); | |
} | |
public function findByMultiConditionsModelLimit($whereData = array(), $orderBy = "id asc") | |
{ | |
return $this->model | |
->where($whereData) | |
->orderByRaw($orderBy) | |
->first(); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Repositories\Contracts; | |
use App\Repositories\RepositoryInterface; | |
/** | |
* Interface UsersRepository. | |
* | |
* @package namespace App\Repositories\Contracts; | |
*/ | |
interface UsersRepository extends RepositoryInterface { | |
public function createUser($request); | |
public function activeUser($request); | |
public function createSession($request); | |
public function deleteSession($request); | |
public function createResetPassword($request); | |
public function updatePassword($id, $request); | |
public function getUser($id); | |
public function updateInfo($user, $request); | |
} |
This file contains hidden or 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
<?php | |
namespace App\Repositories\Eloquent; | |
use App\Repositories\BaseRepository; | |
use App\Repositories\Contracts\UsersRepository; | |
use App\Models\Users; | |
/** | |
* Class UsersRepositoryEloquent. | |
* | |
* @package namespace App\Repositories\Eloquent; | |
*/ | |
class UsersRepositoryEloquent extends BaseRepository implements UsersRepository { | |
/** | |
* Specify Model class name | |
* | |
* @return string | |
*/ | |
public function getModel() { | |
return Users::class; | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace App\Repositories; | |
/** | |
* Description of RepositoryInterface | |
* | |
* @author BaoDo | |
*/ | |
interface RepositoryInterface { | |
/** | |
* Get all column | |
* @param array $columns | |
*/ | |
public function all($columns = array('*')); | |
/** | |
* paginate data | |
* @param integer $perPage | |
* @param array $columns | |
*/ | |
public function first($columns = array('*')); | |
/** | |
* paginate data | |
* @param integer $perPage | |
* @param array $columns | |
*/ | |
public function paginate($perPage = 15, $columns = array('*')); | |
/** | |
* create data | |
* @param array $data | |
*/ | |
public function create(array $data); | |
/** | |
* update data | |
* @param array $data | |
* @param integer $id | |
*/ | |
public function update(array $data, $id); | |
/** | |
* Update or Create an entity in repository | |
* | |
* @throws ValidatorException | |
* | |
* @param array $attributes | |
* @param array $values | |
* | |
* @return mixed | |
*/ | |
public function updateOrCreate(array $attributes, array $values = []); | |
/** | |
* delete data | |
* @param integer $id | |
*/ | |
public function delete($id); | |
/** | |
* deleteWhere | |
* @param array $where | |
*/ | |
public function deleteWhere(array $where); | |
/** | |
* find data | |
* @param integer $id | |
* @param array $columns | |
*/ | |
public function find($id, $columns = array('*')); | |
/** | |
* orderBy | |
* @param string $direction | |
* @param array $columns | |
*/ | |
public function orderBy($column, $direction = 'asc'); | |
/** | |
* findBy column | |
* @param string $field | |
* @param string $value | |
* @param array $columns | |
*/ | |
public function findBy($field, $value, $columns = array('*')); | |
/** | |
* Get by id | |
* @param integer $id | |
*/ | |
public function getById($id); | |
/** | |
* findByField | |
* @param string $field | |
* @param string $value | |
*/ | |
public function findByField($field, $value, $columns = ['*']); | |
/** | |
* findWhere | |
* @param array $where | |
*/ | |
public function findWhere(array $where, $columns = ['*']); | |
/** | |
* Find data by multiple values in one field | |
* | |
* @param $field | |
* @param array $values | |
* @param array $columns | |
* | |
* @return mixed | |
*/ | |
public function findWhereIn($field, array $values, $columns = ['*']); | |
/** | |
* Find data by excluding multiple values in one field | |
* | |
* @param $field | |
* @param array $values | |
* @param array $columns | |
* | |
* @return mixed | |
*/ | |
public function findWhereNotIn($field, array $values, $columns = ['*']); | |
/** | |
* findByMultiConditions | |
* @param string $tableName | |
* @param array $whereData | |
*/ | |
public function findByMultiConditions($tableName, $whereData = array()); | |
/** | |
* paging With Multi Conditions | |
* @param string $tableName | |
* @param array $whereData | |
* @param integer $perPage | |
* @param array $columns | |
*/ | |
public function pagingWithMultiConditions($tableName, $whereData = array(), $perPage = 15, $columns = array('*')); | |
/** | |
* del By Multi Conditions | |
* @param string $tableName | |
* @param array $whereData | |
*/ | |
public function delByMultiConditions($tableName, $whereData = array()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment