laravel-5.4

How to check if validation fail when using form-request in Laravel?

与世无争的帅哥 提交于 2019-12-09 03:24:37
问题 I am trying to write a CRUD for an API. However, when the validation fail, instead of redirecting the user to the home page, I want to return json based response with the errors. I am able to do that using the following code public function store(Request $request) { try { $validator = $this->getValidator($request); if ($validator->fails()) { return $this->errorResponse($validator->errors()->all()); } $asset = Asset::create($request->all()); return $this->successResponse( 'Asset was

How do I validate Array inputs in Laravel 5.0

老子叫甜甜 提交于 2019-12-09 02:19:28
I have a table, where the user can fill in information. However, the user can add rows and/or delete rows. I used a cloning function for that. My html looks like: <input type="text" class="form-control" name="TB1_a[]"> <input type="text" class="form-control" name="TB1_b[]"> As you can see, it is an array input. So if the user adds a row, I'll have two values stored in TB1_a[] and TB1_b. Now, I would like to make my rules so that if the user enters information inside TB1_a[0], I would like to make TB1_b[0] required, but valid if both TB1_a[0] and TB1_b[0] are empty. My validation rules: 'TB1_a.

Upgraded to Laravel 5.4 - Some routes now fail?

纵然是瞬间 提交于 2019-12-08 22:00:57
问题 I had a completely working project on Laravel 5.3 , yesterday I upgraded to Laravel 5.4 locally to check all was working and was very happy so put a plan in place to move it live. Where I have now deployed the site on my forge.laravel.com managed servers, most of the routes work okay but when trying to log out I get the following error: I'm not quite sure what the issue actually is. This site works totally fine locally. Can anyone point me in the right direction? 回答1: As a quick fix (after

Laravel- use @foreach in markdown mail

倾然丶 夕夏残阳落幕 提交于 2019-12-08 17:26:35
问题 I am trying to use @foreach loop inside markdown template for sending mails. While using HTML tags inside @foreach, it is not rendered properly @component('mail::message') These are the latest contents in our website @foreach($results as $type => $result) <h4>{{ $result['name'] }}</h4> @endforeach Thanks,<br> {{ config('app.name') }} @endcomponent In the received mail, the <h4> tag will be displayed as, <h4>Article</h4> Markdown is not getting processed when it's placed inside @foreach loop.

laravel - redirecting three different user types/roles to different pages

☆樱花仙子☆ 提交于 2019-12-08 14:08:33
问题 I use laravel 5.4 and I want to redirect these three different types of users to different pages Schema Types +-------+-------------+ | id | name | +-------+-------------+ | 1 | Super Admin | | 2 | Admin | | 3 | Cashier | +-------+-------------+ Users +-------+---------+-------------+ | id | type_id | name | +-------+---------+-------------+ | 1 | 1 | Super Admin | | 2 | 2 | Admin | | 3 | 3 | Cashier | +-------+---------+-------------+ i write code like this use Auth; public function

Composer not installing local package dependencies

心不动则不痛 提交于 2019-12-08 10:40:02
问题 In my Laravel 5.4 composer.json file I have the following that autoloads my custom package. Note, that this package is not published and is being loaded locally. "autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/", "Vendor\\Module\\": "packages/vendor/module/src" } }, And then in my package composer.json file I have the following { "name": "vendor/module", "description": "A custom package", "version": "1.0.0", "type": "project", "authors": [ ],

Take back to login page after successfully reset his/her password in laravel 5.4

假装没事ソ 提交于 2019-12-08 07:58:07
问题 I want to redirect to login page whenever a user successfully reset his/her password in laravel 5.4. Currently it redirects to dashboard page after successfully reset. I looked around all stuff all are saying to place protected $redirectTo = '/home'; in protected $redirectTo = '/'; But it does not give me any solution. 回答1: By default Laravel authenticates the user after they reset their password. So it's impossible to redirect to the login page since only guest users can view the login page.

Laravel 5.4: Password reset token custom length?

独自空忆成欢 提交于 2019-12-08 07:26:19
问题 I am using laravel 5.4 building an API where I email the user a token on password reset if user verified, which user provides before resetting password. Currently the sent token has 64 characters and too large for user to grab, and I'm not sure if laravel has configuration to give a custom length to token? 回答1: The solution is a little bit tricky, ill try to explain the procedure as clearly as possible: STEP 1 - Extend the standard DatabaseTokenRepository Create a class that extends

How to remove quotes from SQL query Laravel?

帅比萌擦擦* 提交于 2019-12-08 07:07:16
问题 I have the following query: $this->data = \DB::table('months')->select(DB::raw("months.id, COUNT(transactions.id) as total")) ->leftJoin('transactions', function($join) { $join->on('months.id', '=', DB::raw('MONTH(created_at)')) ->on('transactions.doctor_id', '=', $this->user_id); }) ->groupBy('months.id') ->get(); It involks an error on line ->on('transactions.doctor_id', '=', $this->user_id); . It added single quotes for variable $this->user_id . How to avoid this eroros: SQLSTATE[42S22]:

Send email on Bluehost shared hosting

北城余情 提交于 2019-12-08 06:20:44
问题 I have tested Laravel emails on local server with gmail smtp and works fine. MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=myname@gmail.com MAIL_PASSWORD=mypassword MAIL_ENCRYPTION=tls I don't know how to find smtp details on bluhost shared hosting. So anyone knows the setting please comment. This is what i have used currently on the server MAIL_DRIVER=smtp MAIL_HOST=mail.mydomain.com MAIL_PORT=26 MAIL_USERNAME=myname@mydomain.com MAIL_PASSWORD=password MAIL_ENCRYPTION