laravel-5

Get config in Routes?

喜欢而已 提交于 2021-01-28 19:44:38
问题 I want to prefix all my routes with a value from config but I am having trouble getting the value from the config file: Config::get('custom.routes.prefix'); The above gets null even though the value is set in the config file: //config/custom.php 'routes' => => [ 'prefix' => 'whatever', ], How can I get access to config in routes.php? Edit Please note this is not how a question about how to prefix routes, it's how to prefix them with a value from config. 回答1: Maybe just store the route name in

Get a cookie in Laravel 5 middleware

不羁的心 提交于 2021-01-28 19:26:03
问题 I'm trying to retrieve a cookie from a middleware in Laravel 5.3 but it seems like $request->cookie('language') is empty. I'm guessing that it is only set after the middleware runs. I read somewhere that I should use \Cookie::queued('language'), but it's still empty. Is my only option using the $_COOKIE variable? 回答1: When do you set this cookie? Remember that cookies are stored in the browser, so the user needs to get the response in order for you to be able to retrieve the cookie later. You

Laravel 5.5: Execute a method before registration

Deadly 提交于 2021-01-28 14:51:30
问题 I'm using the default laravel authentication. Every user who registeres in my site needs a activation pin. The valid PINs are stored in a different table. Whenever a user registeres, I want to test if the PIN is valid or not. So, is there any method that I can override in RegisterController that executes before regstering the user? 回答1: Yes. You can override protected register method in RegisterController. This is a simple solution. I do this to validate params, save a new user, and force

SQLSTATE[HY000] [2002] Invalid argument (SQL: select * from information_sch ema.tables where table_schema = mamaput and table_name = migrations)

烈酒焚心 提交于 2021-01-28 13:53:10
问题 I set up my app on my virtual private server and after putting up my configuration file i get this error (2/2) QueryException SQLSTATE[HY000] [2002] Invalid argument (SQL: select * from `categories` where `vendor_id` is null). Here is my .env file APP_NAME=Mamaput APP_ENV=production APP_KEY=base64:oJ7frlsRiP5V5QuFKTwVgpoBkUDze6mZZLwawqgayHk= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://mama-put.com DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=mamaput DB_USERNAME=root DB

Laravel 5.4 required if validation issue

两盒软妹~` 提交于 2021-01-28 09:50:52
问题 I have 2 fields, accepts_usd and price_usd. For price usd I have a validation rule: 'price_usd'=>'integer|required_if:accepts_usd,1', And for accepts_usd: 'accepts_usd'=>'boolean|required', When I want to store data if I set accepts_usd to false it still asks for price_usd. whats the issue here? What am I doing wrong? 回答1: you need to change your code to 'price_usd'=>'integer|required_if:accepts_usd,==,1', 回答2: From laravel docs: required_if:anotherfield,value,... The field under validation

Laravel 5.4 required if validation issue

非 Y 不嫁゛ 提交于 2021-01-28 09:43:28
问题 I have 2 fields, accepts_usd and price_usd. For price usd I have a validation rule: 'price_usd'=>'integer|required_if:accepts_usd,1', And for accepts_usd: 'accepts_usd'=>'boolean|required', When I want to store data if I set accepts_usd to false it still asks for price_usd. whats the issue here? What am I doing wrong? 回答1: you need to change your code to 'price_usd'=>'integer|required_if:accepts_usd,==,1', 回答2: From laravel docs: required_if:anotherfield,value,... The field under validation

How to add extra data in response if Validation fails in FormRequest Laravel

試著忘記壹切 提交于 2021-01-28 09:31:05
问题 I need to add custom tag in response if the validation fails in FormRequest. <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class StoreMessage extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'name' => 'required|max:100', 'email' => 'required|email'

How to add extra data in response if Validation fails in FormRequest Laravel

空扰寡人 提交于 2021-01-28 09:28:52
问题 I need to add custom tag in response if the validation fails in FormRequest. <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class StoreMessage extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'name' => 'required|max:100', 'email' => 'required|email'

Laravel get last row value form many table in one to Many relationship

£可爱£侵袭症+ 提交于 2021-01-28 08:56:27
问题 I am building an application which has a model with one to many relationship. In the model, the student table has one to many relationship with student address details. I want to retrieve the last row from address details table. I am stuck on how to retrieve that data. I could not work out from similar answer on this website. My current solution is this $students = Student::with('visaDetails', 'addresses', 'instituteDetails', 'subAgents', 'staffDetails', 'commissionDetails', 'comments')-

Laravel get last row value form many table in one to Many relationship

自闭症网瘾萝莉.ら 提交于 2021-01-28 08:43:43
问题 I am building an application which has a model with one to many relationship. In the model, the student table has one to many relationship with student address details. I want to retrieve the last row from address details table. I am stuck on how to retrieve that data. I could not work out from similar answer on this website. My current solution is this $students = Student::with('visaDetails', 'addresses', 'instituteDetails', 'subAgents', 'staffDetails', 'commissionDetails', 'comments')-