Chron

Chron

Member Since 7 Months Ago

Experience Points 7,950
Experience Level 2

2,050 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 25
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

22 Jul
1 day ago

Chron started a new conversation Is There A Way To Use `except` And `only` On Route Groups?

Like this?


Route::group(['middleware' => ['web']['except' => ['index']]], function (){
    //SomeControllers
    Route::group(['middleware' => ['admin']], function (){
    //Other controllers
    });
});

21 Jul
2 days ago

Chron left a reply on How To Add Multiple Error Messages Inside A Custom Request?

Check all fields match their own rules, then check the combination

Where should I put the combined validation?

Chron left a reply on How To Add Multiple Error Messages Inside A Custom Request?

but the fields are dependent to each other

Chron left a reply on How To Add Multiple Error Messages Inside A Custom Request?

But how can I give the fields their errors? For example..

private method() {
            $room_appointment = Appointment::whereHas('rooms', function($query){
            $query->where('name', $this->room);
        });
        if($room_appointment->doesntExist()) {
        //-------------------------------this error should be in room fields
        }else{
            foreach ($room_appointment as $room){
                if ($this->start >= 0700 && $this->end <= 1800) {
                        return true;
                 }else{
        //-------------------------------this error should be in time fields
                }
            }
        }
}

Chron left a reply on How To Add Multiple Error Messages Inside A Custom Request?

I actually didn't think of that. I'll try it.

Chron left a reply on How To Add Multiple Error Messages Inside A Custom Request?

    public function passes($attribute, $value)
    {
        $appointment = Appointment::where(['start_time' => $this->start_time,'end_time' => $this->end_time])->whereHas('rooms', function($query) {
            $query->where('name', $this->room);
        });
        if ($appointment->doesntExist()) {
            return $this->checkSched();
        }
    }


private method() {
            $room_appointment = Appointment::whereHas('rooms', function($query){
            $query->where('name', $this->room);
        });
        if($room_appointment->doesntExist()) {
            return true;
        }else{
            foreach ($rooms as $room){
                if ($this->start >= 0700 && $this->end <= 1800) {
                    if (($this->start < $room->start_time && $this->end < $room->end_time ||
                        $this->start > $room->start_time && $this->end > $room->end_time) &&
                        $this->start >= $room->end_time && $this->end <= $room->start_time
                    ) {
                        return true;
                    }
                }
            }
        }
}
20 Jul
3 days ago

Chron started a new conversation How To Add Multiple Error Messages Inside A Custom Request?

Inside my custom request, I have a custom rule and it runs multiple conditions. How can I add error messages to each of them?

Chron started a new conversation How To Validate Multiple Different Fields Using Only One Request?

I have 3 fields that are dependent to each other.

I have this in my custom request..

'name' => [new Rule($this->place, $this->age, $this->name)],
'age' => [new Rule($this->place, $this->age, $this->name)],
'place' => [new Rule($this->place, $this->age, $this->name)],

But when it returns an error, it will flash 3 times, I want it to only output the error one time. Are there any cleaner ways to do this?

19 Jul
4 days ago

Chron left a reply on Validation Errors Not Showing

This plugin seems it has conflicts with the framewok. Do you have any recommendations with multiselect inputs?

Chron left a reply on Validation Errors Not Showing

I already have them in my other select inputs, but it doesn't render the old values.

<div class="col">
<div class="form-group">
<label for="sections">Sections</label>
<div class="rounded {{ $errors->has('sections')? 'border border-danger' : '' }}">
<div class="input-group">
<select id="sections" name="sections[]" multiple="multiple"  class="w-100{{ $errors->has('sections')? ' is-invalid' : '' }}"">
@foreach($sections as $section)
<option value="{{ $section->id }}" {{ old('sections') === $section->id? 'selected' : ''}}>{{ $section->name }}</option>
@endforeach
</select>
</div>
</div>
@if ($errors->has('sections'))
<span class="invalid-feedback d-block text-md-left" role="alert">
<strong>{{ $errors->first('sections') }}</strong>
</span>
@endif
</div>
</div>

Chron left a reply on Validation: Ignore An ID From Table

Maybe this is what you're looking at?

https://laravel.com/docs/5.8/validation#rule-unique

If the data is already exist in the database then it will throw an error.

Chron left a reply on Validation Errors Not Showing

The errors are showing when I flash them but it doesn't change the style of the select box, not showing errors under the inputs and not keeping the old values.

Chron left a reply on Validation Errors Not Showing

not working

Chron started a new conversation Validation Errors Not Showing

I'm using this plugin, https://github.com/davidstutz/bootstrap-multiselect/

Here's the code..

                <div class="col">
<div class="form-group">
<label for="days">Days</label>
<div class="input-group{{ $errors->has('days')? ' border-danger' : '' }}">
    <select id="days" name="days[]" multiple="multiple"  class="w-100{{ $errors->has('days')? ' border-danger' : '' }}">
    <option value="Monday">Monday</option>
    <option value="Tuesday">Tuesday</option>
    <option value="Wednesday">Wednesday</option>
    <option value="Thursday">Thursday</option>
    <option value="Friday">Friday</option>
    </select>
    @if ($errors->has('days'))
    <span class="invalid-feedback" role="alert">
        <strong>{{ $errors->first('days') }}</strong>
    </span>
    @endif
      </div>
   </div>
</div>

What can I do to make this work? Are there any alternatives that respects laravel's validation messages?

18 Jul
5 days ago

Chron started a new conversation Mutators And Accessors On Time Not Working

I'm trying to parse the time with a format of 'hi' but the methods are being ignored..

    public function setStartTime($value) {
        $this->attributes['start_time'] = Carbon::parse($value)->format('hi');
    }
    public function setEndTime($value) {
        $this->attributes['end_time'] = Carbon::parse($value)->format('hi');
    }
    public function getEndTime($value) {
        return Carbon::parse($value)->format('hi');
    }
    public function getStartTime($value) {
        return Carbon::parse($value)->format('hi');
    }
17 Jul
6 days ago

Chron left a reply on How To Obfuscate Ids?

I just want it to show to the users the UUID rather than the original ID, but when storing, it will be back to the original key.

Chron started a new conversation How To Obfuscate Ids?

How can I obfuscate ids from the user? But at the same time, I need the ids to run a logic

I have this in a form that grabs ids

//---------------Customer Blade
<select name="customer">
@foreach($customers as $c)
    <option value="{{ $c->id }}">{{ $c->name }}</option>
@endforeach
</select>


//---------------Customer Controller
$companies = Customer::whereIn('id',request('customer'))->get();

I want to use UUIDs but they are autogenerated every time.

13 Jul
1 week ago

Chron started a new conversation Truncate Text With Image

Is there a way to truncate the image from wysiwyg? Like blurring the part that is getting truncated. I tried using str_limit($post->body, 150) but I'm getting a "=""> string.

12 Jul
1 week ago

Chron left a reply on Does Laravel Has Validation For Names?

Only required? Doesn't that only escape spaces but not special chars?

Chron started a new conversation Does Laravel Has Validation For Names?

It should be, because why not? Most of us here at least for once, we create an app that needs user's name. I don't get it why they put alpha_dash but not alpha with spaces. I really don't know why I'm asking in the first place because there's already regex.

Chron left a reply on Is There A Way To Extend Validation Rules?

Yeah, I already did that. But I feel like its repetitive because of the similar fields.

11 Jul
1 week ago

Chron started a new conversation Is There A Way To Extend Validation Rules?

I have two create controllers, one for admin and one for customers.

They have similar fields but the customer has extra fields. I'm validating their inputs in one custom request..

    public function rules()
    {
        return [
            'firstname' =>      'required|string|min:2',
            'middlename' =>     'required|regex:/(^([_])$|^([a-zA-Z])+$)/',
            'lastname' =>       'required|string|min:2',
        ];
    }

Those are the validation rules for both admin and customers, but like I said, I have extra fields for the customer like 'type' and 'status'.

How can I use the base custom validation and extend it in my CustomerController to create other specific validations?

Chron left a reply on Email Verification Problem

Reviving this thread to prevent reposts.

@snapey Is modifying verify method with this okay?

public function verify(Request $request)
{
    $user = User::find($request->route('id'));

    if ($user->markEmailAsVerified())
        event(new Verified($user));

    return redirect($this->redirectPath())->with('verified', true);
}
10 Jul
1 week ago

Chron left a reply on Verify Email Address Redirect When Not Logged In

Well you can override the default route from Laravel in your own routes file and add the auth middleware.

I already had that inside of the controllers.

Chron started a new conversation Verify Email Address Redirect When Not Logged In

For example, I have this verification link.

http://localhost:8000/customer/email/verify/5?expires=1562735461&signature=e1fa4041febb93926d09fab13c743b27b5cfb0c4a36c84d1147d11d2bd480c1d

If the user isn't logged in yet, it should redirect to the /customer/login page. Is there a way to do that?

09 Jul
2 weeks ago

Chron left a reply on Redirect Not Working Properly In Reset Password Form

ForgotPasswordController uses SendsPasswordResetEmails trait ResetPasswordController uses ResetsPasswords trait.

Chron left a reply on Redirect Not Working Properly In Reset Password Form

Route::namespace('Admin')->group(function (){           
    Route::namespace('AdminAuth')->group(function (){
        Route::post('login', '[email protected]');
        Route::prefix('admin')->group(function (){
            Route::post('password/email', '[email protected]')->name('admin.password.email');
            Route::get('password/reset', '[email protected]')->name('admin.password.request');
            Route::post('password/reset', '[email protected]')->name('admin.password.update');
            Route::get('password/reset/{token}', '[email protected]')->name('admin.password.reset');
        });
    });
});

Route::namespace('Customer')->group(function (){            
    Route::namespace('CustomerAuth')->group(function (){
        Route::post('login', '[email protected]');
        Route::prefix('customer')->group(function (){
            Route::post('password/email', '[email protected]')->name('customer.password.email');
            Route::get('password/reset', '[email protected]')->name('customer.password.request');
            Route::post('password/reset', '[email protected]')->name('customer.password.update');
            Route::get('password/reset/{token}', '[email protected]')->name('customer.password.reset');
        });
    });
});

Chron left a reply on Redirect Not Working Properly In Reset Password Form

I have two file in session/framework/sessions, first _previous is _previous";a:1:{s:3:"url";s:21:"http://localhost:8000"; second _previous _previous";a:1:{s:3:"url";s:42:"http://localhost:8000/admin/password/reset";}s:6:

Chron left a reply on Redirect Not Working Properly In Reset Password Form

Yep. back isn't working for me so I use current url.

Chron left a reply on Redirect Not Working Properly In Reset Password Form

I'm not using route name. I'm using current path..

return redirect(url()->current())

Chron left a reply on Redirect Not Working Properly In Reset Password Form

protected function sendResetFailedResponse(Request $request, $response)
    {
        return redirect(url()->current())
        ->withInput($request->only('email'))
        ->withErrors(['email' => trans($response)]);
    }

I already did that, but it just redirect to /

Chron started a new conversation Redirect Not Working Properly In Reset Password Form

How can I change the redirect in ResetPasswordController when the request didn't passed or the credentials are correct?


class ResetPasswordController extends Controller
{
    use ResetsPasswords;

    protected $redirectTo = '/dashboard';
    public function __construct()
    {
        $this->middleware('guest');
    }

    public function showResetForm(Request $request, $token = null)
    {
        return view('admin.passwords.reset')->with(
            ['token' => $token, 'email' => $request->email]
        );
    }

    protected function sendResetLinkResponse(Request $request, $response)
    {
        return redirect('/admin/login')->with('message', trans($response));
    }

    protected function sendResetFailedResponse(Request $request, $response)
    {
        return redirect(url()->current())
        ->withInput($request->only('email'))
        ->withErrors(['email' => trans($response)]);
    }

Chron started a new conversation How To Cascade Delete If Using A Polymorphic Table?

I have an accounts table and it is being shared by multiple tables like admin, customers etc. Is there a way to copy the behavior of foreign constraints? Like when I deleted an admin account in accounts table, it will automatically delete the joined data in admins table.

08 Jul
2 weeks ago

Chron left a reply on Is It Possible To Reference Multiple Tables?

So there's no need for a foreign key when using polymorphic relationship?

Chron left a reply on Is It Possible To Use Other Columns In Auth?

Ohh, sorry. It's just example. I have a polymorphic column named accountable_id they're connected to the models; Admin, Customer and other users...

Chron left a reply on Is It Possible To Use Other Columns In Auth?

It will still have the password but replace the email/username with for example customer_id

Chron started a new conversation Is It Possible To Use Other Columns In Auth?

I want to use one of the column names of the table, I want to use a polymorphic id in replace of email/username. Is that possible?

Chron started a new conversation Is It Possible To Reference Multiple Tables?

I want the user_id to grab all the id from 'admin', 'customer', and other user tables..

Can it be done with something like this?

$table->foreign('user_id')->references('id')->on('admins','customers','other-users')->onDelete('cascade');
07 Jul
2 weeks ago

Chron left a reply on Route [password.reset] Not Defined.

The Reset Notification uses this..

route('password.reset', ['token' => $this->token], false)))

I have 6 routes that has the name of password.reset so that's why I'm getting wrong url.

Chron left a reply on Route [password.reset] Not Defined.

Yep, they're prefixed already.

Route::namespace('Admin')->group(function (){
    Route::prefix('admin')->group(function (){
        Route::namespace('AdminAuth')->group(function (){
            Route::post('login', '[email protected]');

            Route::post('password/email', '[email protected]')->name('password.email');
            Route::get('password/reset', '[email protected]')->name('password.request');
            Route::post('password/reset', '[email protected]')->name('password.update');
            Route::get('password/reset/{token}', '[email protected]')->name('password.reset');
        });
    });
});


Route::namespace('Customer')->group(function (){
    Route::prefix('customer')->group(function (){
        Route::namespace('CustomerAuth')->group(function (){
            Route::post('login', '[email protected]');

            Route::post('password/email', '[email protected]')->name('password.email');
            Route::get('password/reset', '[email protected]')->name('password.request');
            Route::post('password/reset', '[email protected]')->name('password.update');
            Route::get('password/reset/{token}', '[email protected]')->name('password.reset');
        });
    });
});

Chron left a reply on Route [password.reset] Not Defined.

Here are the routes now..

Route::namespace('AdminAuth')->group(function (){
            Route::post('login', '[email protected]');

            Route::post('password/email', '[email protected]')->name('password.email');
            Route::get('password/reset', '[email protected]')->name('password.request');
            Route::post('password/reset', '[email protected]')->name('password.update');
            Route::get('password/reset/{token}', '[email protected]')->name('password.reset');
});

Route::namespace('CustomerAuth')->group(function (){
            Route::post('login', '[email protected]');

            Route::post('password/email', '[email protected]')->name('password.email');
            Route::get('password/reset', '[email protected]')->name('password.request');
            Route::post('password/reset', '[email protected]')->name('password.update');
            Route::get('password/reset/{token}', '[email protected]')->name('password.reset');
});

I don't get the error but when I go reset a customer user I get to another user's reset route.

Chron left a reply on Sometimes|required Not Working

I made the gender field, radio input, that is part of master_create blade,'sometimes' and the error didn't show up.

Chron left a reply on Sometimes|required Not Working

Hmm, does the sometimes work if the input type isn't text? Because I have select and radio inputs.

Chron left a reply on Sometimes|required Not Working

I have them, I can dd them when I individually call them.

Chron left a reply on Sometimes|required Not Working

They're not getting included in the dd. I wonder why? Hmm.. Here's the hierarchy..

layouts(folder)
    -master.blade.php  // for general rendering
    -master_create.blade.php // form for creating users

master_create is the template I'm using, I added a yield inside the file for addtional fields... The form action for the master_create is a laravel slot so I declared each of the users' slots in their respective files.

master_create blade

<div class="card-body">
    <form method="POST" action="{{ $route }}">
        @csrf
        @yield('additional_fields')
    </form>
</div>

Here's one of them..

@section('card_header')
    <i class="fas fa-fw fa-users"></i>
    Add Customer
@endsection
@component('layouts.master_create')
    @slot('route')
        {{ route('customer.register') }}
    @endslot
@section('additional_fields')
    <div class="form-row">
        ... //additional fields
    </div>
@endsection

Chron started a new conversation Sometimes|required Not Working

I have this in my CreationRequest.php

public function rules()
    {
        return [
            'firstname' =>      'required|string|min:2',
            'middlename' =>     'nullable|string|min:2',
            'lastname' =>       'required|string|min:2',
            'sex' =>            'required|string|in:Male,Female',
            'status' =>         'sometimes|required',
            'year_level' =>     'sometimes|required',
            'email' =>          'required|email|unique:accounts',
        ];
    }

status and year_level field are active in one of my forms but I get no error except the other fields.

Chron left a reply on Bug When I Manually Login Users

I tried copying the default login function of the laravel auth and just modify the params but I'm still getting redirected to the home and not logged in.

06 Jul
2 weeks ago

Chron left a reply on Trying To Get Property 'id' Of Non-object

solved it by adding

if($account != null && $user != null){
    return ($account->id === $user->account_id);
}
else{
    return false;
}

However, are there shorter code for this?

Chron started a new conversation Trying To Get Property 'id' Of Non-object

I have this validation request..

 public function rules()
    {
        return [
            'email' => [
                'required','email',
                Rule::exists('accounts')->where(function ($query) {
                    $query->where('account_type', 'Admin');
                }),
            ],
            'id' => [
                'required', 'numeric',
                Rule::exists('admins'),
                new CheckAdminID($this->email)
            ],
        ];
    }

CheckAdminID.php

protected $email;
    public function __construct($email)
    {
        $this->email = $email;
    }

    public function passes($attribute, $value)
    {
        $account = Account::where('email', $this->email)->first();
        $user = Admin::where('id', $value)->first();

        return ($account->id === $user->account_id);
    }

I've entered a non-existent email in the email, then it threw that error. I expect it to fail before it reach the CheckAdminID in the id and the last validation in the email because I've entered both non-existent email and id. Here's the logic, before the user can reset the password, the user must type its email and its user_id. The admins table has account_id, so that will be used to compare with the accounts table id.

Chron left a reply on Route [password.reset] Not Defined.

The other two methods you changed only come into play once the form has been validated - so it won't be those causing redirection to home.

I also changed the redirect of the validation. I hardcoded it with 'admin/password/reset' so if the validation passed or not, it will get redirected to that path.