while(true)
{
doWork();
sleep(1);
}
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php artisan command:start
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
stopwaitsecs=3600
// https://laravel.com/docs/8.x/authentication#invalidating-sessions-on-other-devices
Auth::logoutOtherDevices($currentPassword);
// php artisan make:middleware LogoutUsers
// app/Http/Kernel.php -> $middlewareGroups -> web
<?php
namespace App\Http\Middleware;
use Auth;
use Closure;
class LogoutUsers
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!auth()->check()) {
return $next($request);
}
$user = Auth::user();
if ($user->logout === false) {
$user->update(['logout' => true]);
Auth::logout();
return redirect()->route('login');
}
return $next($request);
}
}
//текущий юзер
$user = Auth::user();
//выход конкретного юзера
$userToLogout = User::find(5);
Auth::setUser($userToLogout);
Auth::logout();
//возвращаем текущего юзера
Auth::setUser($user);
class Listing extends Eloquent
{
public function model()
{
return $this->belongsTo('Model', 'model_id');
}
}
class Model extends Eloquent
{
public function manufacturer()
{
return $this->belongsTo('manufacturer');
}
}
class Manufacturer extends Eloquent
{
}
$listings = Listing::with('model.manufacturer')->all();
foreach($listings as $listing) {
echo $listing->model->manufacturer->name;
}
class Listing extends Eloquent
{
public function model()
{
return $this->belongsTo('Model', 'model_id');
}
public function modelManufacturer()
{
return $this->belongsTo('Model', 'model_id')
->join('.......')
->select('manufacturer.*');
}
}
<?php
namespace App\Http\Middleware;
use Closure;
class HttpsProtocol
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$request->secure()) {
return redirect()->secure($request->getRequestUri(), 301);
}
return $next($request);
}
}
APP_URL=https://site.ru
public function login()
{
//находим номер
$phone = Phones::where('phone', $phone)->with('user')->firstOrFail();
//BelongTo
$user = $phone->user;
//проверяем пароль
if (!Hash::check($password, $user->password)) return false;
//авторизуем
auth()->login($user, true);
//перенаправляем
return redirect()->route('home')->with('message', 'Вы успешно вошли');
}
//AppServiceProvider.php
Validator::extend('current_password', function ($attribute, $value, $parameters, $validator) {
return Hash::check($value, auth()->user()->password);
}, "Неверный пароль, попробуйте еще раз!");
//controller
$validatedData = $request->validate([
'old_password' => 'required|string|current_password',
]);
//...