Asked  7 Months ago    Answers:  5   Viewed   33 times

Recently I start to use laravel 5.3 to write a blog, but I have a question after run php artisan make:auth

when I run this, it will generate routes in my web.php

this is the code in it:

Auth::routes();

Route::get('/home', 'HomeController@index');

Then I run php artisan route:list, I find lots of actions, like LoginController@login...

But I didn't find these actions in my AppHttpControllersAuth, where are these?

And also what is the Auth::routes() stand for, I can't find the routes about Auth.

I need someone help, thank you to answer my question

 Answers

73

Auth::routes() is just a helper class that helps you generate all the routes required for user authentication. You can browse the code here https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php instead.

Here are the routes

// Authentication Routes...
$this->get('login', 'AuthLoginController@showLoginForm')->name('login');
$this->post('login', 'AuthLoginController@login');
$this->post('logout', 'AuthLoginController@logout')->name('logout');

// Registration Routes...
$this->get('register', 'AuthRegisterController@showRegistrationForm')->name('register');
$this->post('register', 'AuthRegisterController@register');

// Password Reset Routes...
$this->get('password/reset', 'AuthForgotPasswordController@showLinkRequestForm');
$this->post('password/email', 'AuthForgotPasswordController@sendResetLinkEmail');
$this->get('password/reset/{token}', 'AuthResetPasswordController@showResetForm');
$this->post('password/reset', 'AuthResetPasswordController@reset');
Wednesday, March 31, 2021
 
revive
answered 7 Months ago
27

Haven't tried that, but in general array fields you usually write like this: program.*, so maybe something like this will work:

  $validator = Validator::make($request->all(),[
        'program'           => 'required',
        'music_instrument'  => 'required_if:program.*,in:Music'
  ]);

If it won't work, obviously you can do it also in the other way for example like this:

$rules = ['program' => 'required'];

if (in_array('Music', $request->input('program', []))) {
    $rules['music_instrument'] = 'required';
}

$validator = Validator::make($request->all(), $rules);
Wednesday, March 31, 2021
 
AlterPHP
answered 7 Months ago
45

Change your blade.php

<div class="md-card-content">
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $samples[0]['COUNT'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2017 YTD</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $samples[1]['COUNT'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2018 YTD</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $samples[2]['COUNT'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2017 Full Year</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />

</div>
Wednesday, March 31, 2021
 
matthy
answered 7 Months ago
44

I think the easiest way would be creation your own validation rule. It could looks like.

Validator::extend('empty_if', function($attribute, $value, $parameters, IlluminateValidationValidator $validator) {

    $fields = $validator->getData(); //data passed to your validator

    foreach($parameters as $param) {
        $excludeValue = array_get($fields, $param, false);

        if($excludeValue) { //if exclude value is present validation not passed
            return false;
        }
    }

    return true;
});

And use it

    $this->validate($request, [
    'name'  =>  'required|max:255',
    'url'   =>  'empty_if:route|url',
    'route' =>  'empty_if:url|route',
    'parent_items'=>  'sometimes|required|integer'
]);

P.S. Don't forget to register this in your provider.

Edit

Add custom message

1) Add message 2) Add replacer

Validator::replacer('empty_if', function($message, $attribute, $rule, $parameters){
    $replace = [$attribute, $parameters[0]];
    //message is: The field :attribute cannot be filled if :other is also filled
    return  str_replace([':attribute', ':other'], $replace, $message);
});
Saturday, May 29, 2021
 
Oshrib
answered 5 Months ago
25

You need to specify html key in the first parameter:

Mail::send( ['html' => 'emails.newinvoice'], ['text' => $emailtext], 
//           ^^^^

Also replace auto-escaped block {{ }} with unescaped {!! !!} in the template:

<p> {!! $text !!} </p>
Wednesday, August 11, 2021
 
rvictordelta
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :