laravel

Laravel 403 forbidden on custom Request validation

こ雲淡風輕ζ 提交于 2021-02-20 19:01:46
问题 I've followed the docs here: https://laravel.com/docs/5.8/validation#form-request-validation I created a custom request StoreName php artisan make:request StoreName Then added the following validation rules: public function rules() { return [ 'name' => 'required|max:255|min:4' ]; } Then as per the documentation type-hinted this in my controller: public function store(StoreName $request) { $validated = $request->validated(); } However, when I send a post request to this endpoint I'm returned a

Unable to create or change a table without a primary key - Laravel DigitalOcean Managed Database

て烟熏妆下的殇ゞ 提交于 2021-02-20 14:56:16
问题 I've just deployed my app to DigitalOcean using (Managed Database) and I'm getting the following error when calling php artisan migrate SQLSTATE[HY000]: General error: 3750 Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before

With() vs Compact() in Laravel

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-20 10:12:41
问题 Is there any difference between with() and compact() ? Which one is more efficient ? 回答1: with() is a Laravel function and compact() is a PHP function and have totally different purposes. with() allows you to pass variables to a view and compact() creates an array from existing variables given as string arguments to it. See compact() for more info on this matter. 回答2: with() is a method made available by method from one of their classes while compact() is a method that is available by default

Laravel command cannot call $this->info() in child class

徘徊边缘 提交于 2021-02-20 06:07:06
问题 I'm just starting out with the basic concepts OO in PHP, Foo.php class Foo extends Command { public function __construct() { parent::__construct(); } public function fire() { $bar = new Bar(); } } Bar.php class Bar extends Foo { public function __construct() { parent::__construct(); $this->info('Bar'); } } When I run Foo::fire() it gives: Call to undefined method Foo::__construct() . But Foo clearly has a constructor, what am I doing wrong? Another thing I suspect is that it might be a

Laravel viaRemember always returning false

余生颓废 提交于 2021-02-20 04:16:14
问题 I've had trouble with keeping my users logged in, so I did some testing and I noticed that the function viaRemember always returns false . This is my login controller function with all the irrelevant code stripped off: public function postSignin(Request $request, AppMailer $mailer) { $this->validate($request, [ 'email' => 'required', 'password' => 'required', ]); $username = $request->get('email'); $password = $request->get('password'); $field = filter_var($username,FILTER_VALIDATE_EMAIL)?

Laravel 5.7 Send an email verification on newly created user

这一生的挚爱 提交于 2021-02-20 04:07:55
问题 Based on this documentation you can easily create a user email verification when someone signing up by them self, but how to send an email verification when admins created the account for their users? I already tried with this approach <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; use Illuminate\Foundation\Auth\VerifiesEmails; class TeacherController extends Controller { use VerifiesEmails; ... // Other basic functions public function

Laravel 5.7 Send an email verification on newly created user

心不动则不痛 提交于 2021-02-20 04:06:03
问题 Based on this documentation you can easily create a user email verification when someone signing up by them self, but how to send an email verification when admins created the account for their users? I already tried with this approach <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; use Illuminate\Foundation\Auth\VerifiesEmails; class TeacherController extends Controller { use VerifiesEmails; ... // Other basic functions public function

Laravel 5.6 Method Illuminate\Database\Query\Builder::createToken does not exist

痞子三分冷 提交于 2021-02-20 03:54:31
问题 I am trying to create API authentication using Passport but I can not seem to create a token when a user is being registered using createToken (). I have already checked I have included HasApiTokens but still gives same error. ERROR Method Illuminate\Database\Query\Builder::createToken does not exist App\User namespace App; use Laravel\Passport\HasApiTokens; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable {

Creating attendance in laravel

本小妞迷上赌 提交于 2021-02-20 02:59:05
问题 Well.. I have created a attendance system for salesman and structure of my database is users (id, name) attendances (att_id, user_id, created_at) This is the data that I have and used in creating the attendance, $final = array:2 [▼ 0 => array:3 [▼ "id" => 6 "name" => "Talha Munshi" "attendance" => array:4 [▼ 0 => array:3 [▼ "attendance" => "P" "advance" => "0" "date" => Carbon {#250 ▼ +"date": "2017-07-16 08:07:00.000000" +"timezone_type": 3 +"timezone": "Asia/Karachi" } ] 1 => array:3 [▼

面试官问:你说说Redis的几个过期策略?

这一生的挚爱 提交于 2021-02-19 10:47:41
在使用redis时,一般会设置一个过期时间,当然也有不设置过期时间的,也就是永久不过期。当设置了过期时间,redis是如何判断是否过期,以及根据什么策略来进行删除的。 设置过期时间 expire key time(以秒为单位) 这是最常用的方式 setex(String key, int seconds, String value) 字符串独有的方式 除了字符串自己独有设置过期时间的方法外,其他方法都需要依靠expire方法来设置时间如果没有设置时间,那缓存就是永不过期如果设置了过期时间,之后又想让缓存永不过期,使用persist key 三种过期策略 定时删除 在设置key的过期时间的同时,为该key创建一个定时器,让定时器在key的过期时间来临时,对key进行删除 优点: 保证内存被尽快释放 缺点: 若过期key很多,删除这些key会占用很多的CPU时间,在CPU时间紧张的情况下,CPU不能把所有的时间用来做要紧的事儿,还需要去花时间删除这些key 定时器的创建耗时,若为每一个设置过期时间的key创建一个定时器(将会有大量的定时器产生),性能影响严重 懒汉式式删除 key过期的时候不删除,每次通过key获取值的时候去检查是否过期,若过期,则删除,返回null。 优点: 删除操作只发生在通过key取值的时候发生,而且只删除当前key,所以对CPU时间的占用是比较少的