aznyouth

aznyouth

Member Since 3 Months Ago

Experience Points
240
Total
Experience

4,760 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
0
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.

Level 1
240 XP
Aug
01
3 months ago
Activity icon

Replied to Can't Update User Email

I'm sorry, I'm kind of new to laravel. so it should be like this?

$user = $this->route('user') ;
Return ['email' => 'unique:users,email,' . $user->id,
        ];

Activity icon

Replied to Can't Update User Email

That's what I thought but it says $user is not defined.

Jul
31
3 months ago
Activity icon

Started a new Conversation Can't Update User Email

Hello everyone,

I just did a CRUD, CRD works well but not the update. When I try to update the email which is unique, it says "The email has already been taken."

However if I change the email, it works well. So I think the problem should be from the validation rules...

Any clues ?

UpdateUserRequest.php

    public function rules()
    {
        return [
            'email' => 'unique:users',
        ];
    }


UsersController.php

    public function update(UpdateUserRequest $request, User $user)
    {
        $user->update([
            'firstname' => $request->firstname,
            'lastname'  => $request->lastname,
            'email'     => $request->email,
            'password'  => Hash::make($request->password)
        ]);

        $notification = array(
            'message'       => 'Utilisateur mis à jour avec succès.',
            'alert-type'    => 'success'
        );
        return redirect(route('users.index'))->with($notification);
    }


create_update.blade.php

        <div class="card-body">
            @include('partials.errors')
            <form action="{{ isset($user) ? route('users.update', $user->id) : route('users.store')}}" method="POST">
                @csrf
                @if(isset($user))
                    @method('PUT')
                @endif
                <div class="form-group">
                    <label for="lastname">Nom</label>
                    <input type="text" class="form-control" name="lastname" id="lastname" value="{{ isset($user) ? $user->lastname : ''}}">
                </div>
                <div class="form-group">
                    <label for="firstname">Prénom</label>
                    <input type="text" class="form-control" name="firstname" id="firstname" value="{{ isset($user) ? $user->firstname : '' }}">
                </div>
                <div class="form-group">
                    <label for="email">Email</label>
                    <input type="text" class="form-control" name="email" id="email" value="{{ isset($user) ? $user->email : '' }}">
                </div>
                <div class="form-group">
                    <label for="password">Password</label>
                    <input type="password" class="form-control" name="password" id="password" value="{{ isset($user) ? $user->password : ''}}">
                </div>
                <div class="text-center">
                    <button type="submit" class="btn btn-success mr-3">Valider</button>
                    <a href="{{ back()->getTargetUrl() }}" class="btn btn-danger">Retour</a>
                </div>
            </form>
        </div>


Thanks in advance

Jul
29
3 months ago
Activity icon

Replied to Redirect After Login

I just checked the commits from your repo. You are duplicating the scaffolded authentication for staff. I don't thnk that's a right way to do it

Activity icon

Replied to Redirect After Login

Funny things is that for $role, I have the right value, either 'admin' or 'user' however It doesn't redirect to the right url ... It always redirect to '/'.

PS: thats a bit mean :/

Activity icon

Replied to Redirect After Login

@munazzil @saurabhd

Both methods don't work :( Please try the github project

Activity icon

Replied to Redirect After Login

It's the same as auth()->user()->role but you don't need to use the facade Auth.

Please check the github code

Activity icon

Started a new Conversation Redirect After Login

Hi !

I'm new to laravel, so I've been trying few things like create a back office and front with the login as startup page. So I've been trying to redirect to /admin when I'm admin or /user when I'm user.

I have modified the LoginController as suggested in Laravel documentation, I couldn't make it work... Any advises ?

LoginController.php

    use AuthenticatesUsers;

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

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
    public function redirectTo() {
        // User role
        $role = auth()->user()->role;
        // Check user role
        switch ($role) {
            case 'admin':
                return '/admin';
                break;
            case 'user':
                return '/user';
                break;
            default:
                return '/login';
                break;
        }
    }

web.php


Auth::routes();

Route::get('/', '[email protected]')->name('home');

/* BackOffice */
Route::group([
    'prefix' => 'admin',
    'middleware' => [
        'auth',
        'admin',
    ],
], function() {
    Route::get('/', '[email protected]')->name('admin.home');
    Route::get('users/profile', '[email protected]')->name('users.edit-profile');
    Route::put('users/profile', '[email protected]')->name('users.update-profile');
    Route::get('users', '[email protected]')->name('users.index');
    Route::post('users/{user}/make-admin', '[email protected]')->name('users.make-admin');
});


/* FrontOffice */
Route::group([
    'middleware' => [
        'auth',
    ],
], function() {
    Route::get('/user', '[email protected]')->name('user.home');
});

Here is the code https://github.com/AnthonyIp/test_laravel

Thanks in advance

Jul
25
3 months ago
Activity icon

Replied to Dynamic Prefix Routing

That's what I did before but I thought it was not very clean to do it that way...

I will have like thrice the same route just because of the prefix :(

Activity icon

Replied to Dynamic Prefix Routing

I still have the issue with your method.

How do I determine which route it will be on my template ?

<li class="nav-item">
       <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
Jul
24
3 months ago
Activity icon

Replied to Dynamic Prefix Routing

This doesn't work for me.

I found a hint to do it cleanly but It doesn't work, I might miss something.

app\Providers\RouteServiceProvider.php

    public function boot()
    {

        parent::boot();

        Route::bind('brand', function ($value) {
            return Brand::where('slug', $value)->first() ?? abort(404);
        });
    }


routes/web.php

use Illuminate\Support\Facades\Auth;
use \App\Brand;

Route::group([
    'prefix' => '{brand}'
], function () {
    AuthRoutes();
    Route::get('/home', function() {
        return view('welcome');
    });
});

In localhost/{brand}/ which should redirect to localhost/{brand}/login

I have this error :

  • Missing required parameters for [Route: login] [URI: {brand}/login]

My database is populated so {brand} should be replaced by for example nike ?

Activity icon

Started a new Conversation Dynamic Prefix Routing

Hello Guys !

Just to make clear, I'm a noob in Laravel, my question may sound stupid ahah

I'm currently facing an issue with the prefix routing. I'm not sure if I'm doing it right for the routing, can someone give me some advice ?

Here is the context: My website has 2 front and 1 back. All views will kind of be similar, just some section will disappear. Depending on which urls for the homepage we will have, if the user is not authenticated, it should redirect to the login page.

Urls should be like this:

  • localhost/admin -> localhost/admin/login
  • localhost/front1 -> localhost/front1/login
  • localhost/front2 -> localhost/front2/login

web.php

Route::group([
    'prefix' => 'front1'
], function () {
    AuthRoutes();
    Route::get('/', '[email protected]')->name('f1.home');
});

Route::group([
    'prefix' => 'front2'
], function () {
    AuthRoutes();
    Route::get('/', '[email protected]')->name('f2.home');

});

Route::group([
    'prefix' => 'admin',
], function () {
    AuthRoutes();
    Route::get('/', '[email protected]')->name('admin.home');

});

//Auth::routes();

function AuthRoutes()
{
    Route::get('login', 'Auth\[email protected]')->name('login');
    Route::post('login', 'Auth\[email protected]');
    Route::post('logout', 'Auth\[email protected]')->name('logout');
    Route::get('register', 'Auth\[email protected]')->name('register');
    Route::post('register', 'Auth\[email protected]');
    Route::get('password/reset', 'Auth\[email protected]')->name('password.request');
    Route::post('password/email', 'Auth\[email protected]')->name('password.email');
    Route::get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
    Route::post('password/reset', 'Auth\[email protected]')->name('password.update');
    Route::get('email/verify', 'Auth\[email protected]')->name('verification.notice');
    Route::get('email/verify/{id}', 'Auth\[email protected]')->name('verification.verify');
    Route::get('email/resend', 'Auth\[email protected]')->name('verification.resend');
}

How do I redirect to the right view ? Here is what happened :

  • localhost/admin -> localhost/admin/login
  • localhost/front1 -> localhost/admin/login
  • localhost/front2 -> localhost/admin/login

No matter which prefix I am at, it will redirect me to the admin/login

How do I fix this ?

Thanks everyone