Adgower

Adgower

Member Since 1 Month Ago

Oklahoma City

Experience Points
17,860
Total
Experience

2,140 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
171
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 4
17,860 XP
Jul
31
1 week ago
Activity icon

Replied to Generate Dynamic Routes, But Keep Auth

@michaloravec the logout route doesn't work for some reason. The issue is: If I click logout button it works, but if I just type /logout it doesn't work. I assume because it is not submitting that POST request to logout. Any tips? I think it's all good.

Jul
30
1 week ago
Activity icon

Replied to Generate Dynamic Routes, But Keep Auth

Auth::routes();

Route::middleware('auth')->prefix('admin')->group(function () {
    Route::get('/', '[email protected]')->name('dashboard');

    Route::resource('appointments', 'AppointmentController');
    Route::resource('companies', 'CompanyController');
});

Route::get('/{page}', '[email protected]');
Activity icon

Started a new Conversation Generate Dynamic Routes, But Keep Auth

Hey can someone point me in the right direction? I want to be able to use dynamic slugs for a pagemanager concept, but when I setup the routes for it. It breaks the auth routes. What is the best way to do this?

Jul
23
2 weeks ago
Activity icon

Awarded Best Reply on How To Query Users Company Id On Event?

This works, but is there a more efficient way?

$company = Company::whereHas('user', function ($query) {
                $query->where('user_id', Auth::id());
            })->first();

            $course_events = Event::has('courses')->whereHas('users.companies', function ($query) use ($company) {
                $query->where('company_id', $company->id);
            });

            $events = Event::has('services')->whereHas('user.companies', function ($query) use ($company) {
                $query->where('company_id', $company->id);
            })->union($course_events)->where('start_date', '>=', Carbon::now('America/Chicago'))->orderBy('start_date', 'asc')->get();
Jul
21
2 weeks ago
Activity icon

Replied to How To Query Users Company Id On Event?

This works, but is there a more efficient way?

$company = Company::whereHas('user', function ($query) {
                $query->where('user_id', Auth::id());
            })->first();

            $course_events = Event::has('courses')->whereHas('users.companies', function ($query) use ($company) {
                $query->where('company_id', $company->id);
            });

            $events = Event::has('services')->whereHas('user.companies', function ($query) use ($company) {
                $query->where('company_id', $company->id);
            })->union($course_events)->where('start_date', '>=', Carbon::now('America/Chicago'))->orderBy('start_date', 'asc')->get();
Jul
20
2 weeks ago
Activity icon

Started a new Conversation How To Query Users Company Id On Event?

I have a company owner role for users. I want to display the companies users events/appointments to the company owner role. Events can have a user_id, and then another type of event has many users for the event.

How can I make this concept in eloquent:

if (Auth::user()->hasRole('company')) {
            $company = DB::select('select * from companies where user_id = ?', [Auth::id()]);
$events = Event::whereHas('users', function ($query) {
                $query->whereUserId(Auth::id())->where('company_id', '=', $company->id);
            })->orWhere('user_id', Auth::id())->where('company_id', '=', $company->id)->where('start_date', '>=', Carbon::now('America/Chicago'))->orderBy('start_date', 'asc')->get();
}

The table company_user holds the user_id and company_id user model

public function company()
{
  return $this->belongsTo('App\Company');
}

Thanks

Jul
16
3 weeks ago
Activity icon

Replied to Can't Create ForeignId On Users Table

@snapey, but I also want a "company" owner that is why I had an id on the company

Activity icon

Replied to Can't Create ForeignId On Users Table

Okay is it more efficient to put the company associate in a pivot table or on the user model?

Activity icon

Started a new Conversation Can't Create ForeignId On Users Table

Hey I have a users, and companies table.

On the users table I have:

$this->foreignId('company_id')->constrained();

companies table:

$this->foreignId('user_id')->constrained();

Each company can have 1 user as contact, but many users can belong to a company. When I run:

php artisan migrate:fresh

I get:

SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'companies' (SQL: alter table `users` add constraint `users_company_id_foreign` foreign key (`company_id`) references `companies` (`id`))

Why does this not work? If I create a pivot table and remove the company_id off the user table it works fine.

Jul
13
3 weeks ago
Activity icon

Awarded Best Reply on Format Date With Carbon DiffForHumans

Setting the timezone in the now fixed it for me. Is this the best solution?

{{Carbon\Carbon::now('America/Chicago')->diffForHumans($events->first()->start_date)}}

Returns

1 hour after

Which is correct! Thanks for assisting me.

Activity icon

Replied to Format Date With Carbon DiffForHumans

Setting the timezone in the now fixed it for me. Is this the best solution?

{{Carbon\Carbon::now('America/Chicago')->diffForHumans($events->first()->start_date)}}

Returns

1 hour after

Which is correct! Thanks for assisting me.

Activity icon

Replied to Format Date With Carbon DiffForHumans

When I run

{{Carbon\Carbon::now()}}

Returns

"2020-07-13 13:50:05"

Which is off by 5 hours. I set env variable to:

APP_TIMEZONE=America/Chicago

And ran

php artisan config:clear
Activity icon

Replied to Format Date With Carbon DiffForHumans

@mvd it returns "5" I assume hours. Technically it should be 42 minutes ago and if it rounds up 1hr ago

Jul
12
4 weeks ago
Activity icon

Started a new Conversation Format Date With Carbon DiffForHumans

{{Carbon\Carbon::parse($events->first()->start_date)->diffForHumans()}}

Returns 4 hours from now.

The value is

2020-07-13 08:00:00

and current time on is 2020-07-12 22:42

I would like it to return "tomorrow" or even better would be ~9 hrs

Activity icon

Replied to Carbon Adds 7 Minutes To Date Time?

Lawd have mercy. It has been a long day. Thanks.

Activity icon

Started a new Conversation Carbon Adds 7 Minutes To Date Time?

My request returns

"07/13/2020 8:00 AM - 07/17/2020 5:00 PM"

Then explode

$datetimes = explode(' - ', $request->datetimes);

dd($datetimes[0])

"07/13/2020 8:00 AM"

Format string with carbon

\Carbon\Carbon::parse($datetimes[0])->format('d M, H:mA')

Returns

"13 Jul, 08:07AM"
Activity icon

Replied to How To Retrieve A Many To Many Relationship In A Frontend Table

each company has only 1 location right? If this is true switch from many to many to one to one inside your company model create a relationship for

public function location()
{
return $this->belongsTo('App\Location')
}

you could then call it using

{{$company->location->name}}

There are probably better methods to accomplish this, but I believe this will get you started.

Activity icon

Replied to How To Check Model Of Many To Many Polymorphic Association?

How can I create a method that checks a list of methods for not empty, and return the one that is not empty.

Activity icon

Replied to How To Check Model Of Many To Many Polymorphic Association?

Is there a better method to do this?

@forelse ($event->services as $service)
  {{$service->name}}
@empty
@endforelse

@forelse ($event->courses as $course)
  {{$course->name}}
@empty
@endforelse

In the future I would like to add more and check dynamically.

Activity icon

Replied to How To Check Model Of Many To Many Polymorphic Association?

when I run

{{class_basename($event)}}

It returns "Event", but I would like it to return the many to many polymorphic event relationship class for example "Course" or "Service".

Thanks

Jul
10
4 weeks ago
Activity icon

Started a new Conversation How To Check Model Of Many To Many Polymorphic Association?

How do I access many to many Polymorphic association type?

I have events that are schedulable. You can create events for services, and courses. When I Pull the relationship how do I determine what model (service or course) the event belongs to?

My dumb solution right now is to check if each relationship is empty $event->services->isNotEmpty(), $event->courses->isNotEmpty(). This doesn't doesn't seem like the right method, but I am a beginner to laravel, and I don't understand all the options yet. Could someone point me in the right direction?

Thanks

Jun
25
1 month ago
Activity icon

Replied to How Can I Change Md5 Passwords To Bcrypt In Laravel 5.4?

Hey All,

I just wanted to say thanks. I don't know if this is the best method for laravel 7, but it works great. I had the same issue. I needed to migrate users with md5 passwords to bcrypt. This was the simplest solution I found, although the code has slighly changed for the AuthenticatesUsers.php login function. Let me know if there is a better solution or method to accomplish this. I was looking into creating custom controller login etc, but that seemed like too much work. Then I was looking into mutators, but I need to learn more about how those work. I am a beginner.

The method I am currently using is a single column for password method. I have imported my old users into the database using the MD5 hashed passwords in the password column that is migrated with laravel. Then it converts that single value.

Same steps as others have mentioned open AuthenticatesUsers.php file and copy the login function into the LoginController.php

At the top of the file

add:

use Illuminate\Http\Request;
use App\User;

Then inside the login function include the method mentioned above:

// check the md5 password and change md5 to bcrypt if the user was found
        $user = User::where('email', $request->email)
                ->where('password',md5($request->password))
                ->first();
        if (!empty($user->id)) {
            $user->password = bcrypt($request->input('password'));
            $user->save();
        }

Final File:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

use Illuminate\Http\Request;

use App\User;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * Handle a login request to the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
     */
    public function login(Request $request)
    {
        // check the md5 password and change md5 to bcrypt if the user was found
        $user = User::where('email', $request->email)
                ->where('password',md5($request->password))
                ->first();
        if (!empty($user->id)) {
            $user->password = bcrypt($request->input('password'));
            $user->save();
        }

        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if (method_exists($this, 'hasTooManyLoginAttempts') &&
            $this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }
}