Sinres

Member Since 3 Years Ago

Experience Points
2,400
Total
Experience

2,600 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
6
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.

  • Community Pillar

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

Level 1
2,400 XP
May
08
2 days ago
May
07
3 days ago
Activity icon

Started a new Conversation How Get Reset Password Token To Custom Welcome Notification

Hello Guy's!

I trying to create a custom welcome user notification after verified email address. And when user click verify button from email I run event verified and send nother one mail with welcome notification and button for set default password but I don't know how get token for endpoint password/reset/$token

Look this is my code:

<?php

namespace App\Providers;

use App\Listeners\SendWelcomeUserListener;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Events\Verified;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        Verified::class => [
            SendWelcomeUserListener::class,
        ]
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}
<?php

namespace App\Listeners;

use App\Notifications\SendWelcomeUserNotification;
use Illuminate\Auth\Events\Verified;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class SendWelcomeUserListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  Verified  $event
     * @return void
     */
    public function handle(Verified $event)
    {
        $event->user->notify(new SendWelcomeUserNotification());
    }
}
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SendWelcomeUserNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($token)
    {
        $this->token = $token;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail()
    {
        return (new MailMessage)
                    ->subject('Welcome on board!')
                    ->line('Hello! In first you must change your default password to login')
                    ->action('Set your password', url('password/reset',  $this->token))
                    ->line('Thank you!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

I trying to get token by constructor of SendWelcomeNotification class but this is not work because I don't know how can hand over the token

May
05
5 days ago
Activity icon

Replied to How To Except Some Fields From FormRequest

I found a solution in documentation:

In some situations, you may wish to run validation checks against a field only if that field is present in the data being validated. To quickly accomplish this, add the sometimes rule to your rule list:

$v = Validator::make($request->all(), [
    'email' => 'sometimes|required|email',
]);
Activity icon

Replied to How To Except Some Fields From FormRequest

I have response

"message": "The given data was invalid.",
    "errors": {
        "password": [
            "Password field is required!"
        ]
    }

But I used a FormRequest and created custom message. Maybe I must use sometimes.

'password' => 'sometimes|required|string|confirmed|min:8'
Activity icon

Replied to How To Except Some Fields From FormRequest

This is event for email verification. You find this in Laravel Doc.

Activity icon

Started a new Conversation How To Except Some Fields From FormRequest

Hello,

How I can except some fields from Laravel FormRequest?

I try some like this but doesn't work

public function create(StoreUserRegisterRequest $request)
    {
        $user = User::create($request->except(['password']));

        event(new Registered($user));

        return response()->json([
            'message' => 'User has created successfully',
            'data' => $user
        ], 200);
    }
Activity icon

Replied to Change Password At First Login

Thanks @pascual !

I have to think which solution will be the best because I want to send an email with email address verification and after clicking the link, display the success message with the password change form.

Activity icon

Replied to Change Password At First Login

How I can do this when I used Laravel API and for frontend React? This is SPA aplication

Activity icon

Started a new Conversation Change Password At First Login

Hello Guy's,

What is the best way to change password when the user logs in for the first time?

I have an idea to create a new column password_change_at and check if it's null. What do you think about it?

May
04
6 days ago
Activity icon

Replied to Receives A Null Response From Resource - Laravel API

Michal again you save my life haha :-) Why doesn't it work my way? The code looks better then. It works fine in the update method, but am I doing it right?

public function update(Role $role, StoreRoleRequest $request): RoleResource
    {
        $role->fill($request->validated())->save();

        return new RoleResource($role);
    }
Activity icon

Started a new Conversation Receives A Null Response From Resource - Laravel API

Hello Guy's!

I have some problem. When I test my API by Postman I receives a null response when create a new record in database.

This is my store method from Controller:

    public function store(Role $role, StoreRoleRequest $request): RoleResource
    {
        $role->create($request->validated());

        return new RoleResource($role);
    }

And my Resources:

<?php

namespace App\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class RoleResource extends JsonResource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            // 'permissions' => PermissionResource::collection($this->whenLoaded('permissions'))
        ];
    }
}

Response from Postman when created new role:

{
    "data": {
        "id": null,
        "name": null
    }
}

Have any ideas?

Apr
22
2 weeks ago
Activity icon

Replied to Target Class [ReviewController] Does Not Exist.

Try this:

Route::get('addreview', 'App\Http\Controllers\[email protected]')->name('addreview');
Activity icon

Started a new Conversation How To Generate Slug To Use In Code For Roles And Permissions?

Hello Guy's!

I'm using packages spatie/laravel-permission and I don't know how I can generate slug to roles and permission for Laravel API? For Laravel blade we can use @can('write a posts) directives etc. but how use this by Laravel API ... I don't know how. Please explain it to me

Activity icon

Replied to How To Make Better Way Assign Permission To Role

Thanks for help! I think I chose the best solution for me what do you think? :-)

Activity icon

Replied to How To Make Better Way Assign Permission To Role

I like the second solution, but I have to check if the permission or role exists, if not exists give message for API. How I can check if exists with used route model binding?

Activity icon

Started a new Conversation How To Make Better Way Assign Permission To Role

Hello Guys!

I have function to assign permission to role but I wonder how to write it better. It's mainly about references to find (). Any ideas? I'm using package laravel-permission

public function assignPermissionToRole($permission_id, $role_id): JsonResponse
    {
        $role = Role::find($role_id);
        $permission = Permission::find($permission_id);

        if(!$role || !$permission) {
            return response()->json([
                'message' => 'The specified role or permission name does not exist'
            ]);
        }

        $role->givePermissionTo($permission->id);

        return response()->json([
            'message' => 'Permission ' . $permission->name . ' has assigned to role ' . $role->name
        ]);
    }
Apr
21
2 weeks ago
Activity icon

Replied to How To Check Role Has Permission Before Deleted

@tykus thank you ! I forgot the function count() :D Problem solved :-)

Apr
20
2 weeks ago
Activity icon

Started a new Conversation How To Check Role Has Permission Before Deleted

Hello Guys!

I am using the package spatie/laravel-permission

How can I check if a role is assigned permissions before deleting?

I'm trying by destory method like this, but I don't know how to refer to the permission you are looking for

public function destroy($id): JsonResponse
    {
        $role = Role::find($id);

        if($role->hasPermissionTo($role->id)) {
            return response()->json([
                'message' => 'You cannot delete a role that has permissions assigned'
            ]);
        }

        // $role->delete();

        if (request()->expectsJson())
        {
            return response()->json([
                'message' => 'Role has been removed'
            ], 200);
        }
    }