Calid

Calid

Washington DC

Member Since 1 Year Ago

Experience Points 11,560
Experience
Level
Lessons Completed 111
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

15 Sep
2 months ago

Calid left a reply on Custom Redirect After Registration Validation Failure - Call To Undefined Method Illuminate\Http\RedirectResponse::validate()

Thanks you @Snapey , added this to RegisterController.php

    /**
     *
     * Override Trait RegistersUsers : vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php
     *
    */
    public function register(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            return redirect('/register')
            ->withErrors($validator)
            ->withInput();
        }

        event(new Registered($user = $this->create($request->all())));
        $this->guard()->login($user);
        return redirect($this->redirectPath());
    }
14 Sep
2 months ago

Calid started a new conversation Custom Redirect After Registration Validation Failure - Call To Undefined Method Illuminate\Http\RedirectResponse::validate()

I am using modal for registration and login, I want to redirect user to /registration page if validation has an error. I am getting an error

Call to undefined method Illuminate\Http\RedirectResponse::validate()

Here is my RegisterController.php

<?php
namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Auth\RegistersUsers;

use Illuminate\Http\Request;

use Validator;
use Auth;

class RegisterController extends Controller
{

    use RegistersUsers;
    
    protected $redirectTo = '/home';

    
    public function __construct()
    {
        $this->middleware('guest');
    }

    
    protected function validator(array $data)
    {
        $validator = Validator::make($data, [
            'username' => 'required|string|max:255',
            'email' => 'required|email|unique:users,email,'.Auth::id(),
            'password' => 'required|string|min:6',
            'country_id' => 'required|integer|exists:countries,id',
            'mobile' => 'required|numeric|min:6|max:15',
        ]);
        
        
        //return $validator;
        
        if ($validator->fails()) {
            return redirect('/register')
            ->withErrors($validator)
            ->withInput();
        }

    }

    
    
    protected function create(array $data)
    {
            $user = new User;
            $user->username = $data['username'];
            $user->email = $data['email'];
            $user->password = Hash::make($data['password']);
            $user->mobile = $data['email'];
            $user->country_id = $data['country_id'];
            $user->ip = request()->ip();

            if($user->save()) {
            return $user;
            }
    }
}

Thanks

29 Aug
2 months ago

Calid started a new conversation What Is The Most Efficient Way To Return Count Of Relation Records Without Loading Relation

I have subcategory and ads with relations like this:

subcat.php

public function ads() {
        return $this->hasMany(Ad::class, 'subcat_id');
    }

ad.php

public function subcat() {
        return $this->belongsTo(Subcat::class, 'subcat_id');
    }

I am trying to get the count of ads for each subcategory without loading the relation items as they are in hundreds of thousands ...

13 Jul
4 months ago

Calid left a reply on Laravel 5.5 Middleware Question

this is how to redirect in registration controller

class RegisterController extends Controller
{

    use RegistersUsers;

    protected $redirectTo = '/u';
    
    /**
     * conditional redirect user on login.
     */
    protected function redirectTo()
    {
        if (\Session::has('regcode')) {
            return route('RegistrationCode');
        }
        
        return $this->redirectTo;
    }


    public function __construct()
    {
        $this->middleware('guest');
    }
    
    /* rest of the code
    @
    @
    @
    @
    */
    
}

Calid left a reply on Laravel 5.5 Middleware Question

this is how I done it

class LoginController extends Controller
{

    use AuthenticatesUsers;

    protected $redirectTo = '/u';
    
    /**
     * conditional redirect user on login.
     */
     
    protected function redirectTo()
    {
        if (\Session::has('regcode')) {
            return route('RegistrationCode');
        }
        
        if(Auth::user()->hasAnyRole(['admin', 'superadmin', 'sale'])) {
            return route('HomeAdmin');
        }
        
        if(Auth::user()->hasAnyRole(['student', 'free', 'webuser'])) {
            return route('HomeUser');
        }

    }
    
    /* rest of the code 
    @
    @
    @
    @
    */
    
}

Calid left a reply on Updating Database After Sending Email

Thanks @Cronix , I thought of that but wasn't sure if this is the best way to do it and in case mail sent failed it will still update the database , I will give it a try.

@snapey yes I have the user ID in mailable, but wouldn't that require to fire the event every time I call Welcome Mailable class

class welcomeNewUser extends Mailable
{
    use Queueable, SerializesModels;

    public $user;
    public $data;
    

    public function __construct($user, $data)
    {
         $this->user = $user;
         $this->data = $data;
    }


    public function build()
    {
        $subject = 'Welcome To Our Website';
        $fromEmail = '[email protected]';
        $fromName = "Website Name";
        
        return $this->view('emails.welcomeUser')
                ->from($fromEmail, $site)
                ->replyTo($this->user->email, $this->user->firstname)
                ->subject($subject)
                ->with(['user', $this->user], ['data', $this->data]);
    }
}

Calid started a new conversation Updating Database After Sending Email

I am trying to figure out how to update database after sending an email. In my application I need to update column on users table "email_sent" after sending welcome email.

Welcome email is not attached to any event and can be fired from different methods/controllers. what would be the best way to achieve this without adding extra code each time I am calling Welcome Mailable class ... Thank You

05 Nov
1 year ago

Calid left a reply on Is It Possible To Tell Laravel To Lowercase Or Trim All Inputs By Default?

After reading through this post, this is how I done it, appreciate any feedback!

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\TransformsRequest as TransformsRequest;
use Closure;

class SanitizationData extends TransformsRequest
{
    
    protected $except = [
        'password',
        'password_confirmation',
    ];
    
    protected function transform($key, $value)
    {
        
        switch ($key) {
            case "name":
            case "title":
            case "meta_desc":
            case "meta_title":
            case "meta_keywords":
                return filter_var($value, FILTER_SANITIZE_STRING);
        break;
            case "body":
                return htmlentities($value, ENT_COMPAT, "UTF-8", FALSE);
        break;
            case "email":
                return filter_var($value, FILTER_SANITIZE_EMAIL);   
        break;
            case "url":
                return filter_var($value, FILTER_SANITIZE_URL);
        break;
            default:
                return $value;
        }
    }
}

24 Aug
1 year ago

Calid left a reply on Route Model Binding: Check If A Route Parameter Exists In Model

@sugo , any luck figuring a clean way to do this?

28 May
1 year ago

Calid left a reply on Changing The Default Location Of Storage Symlink - Laravel 5.4

Thanks @jijoel , Yes on production site I have the app outside the domain public folder ...

Calid left a reply on Changing The Default Location Of Storage Symlink - Laravel 5.4

Thanks @bashy , it's my first Laravel project so still figuring things out, you pointed my attention to fix the problem. The issue was in filesystems.php has nothing with symlink.

@ehab.aboshehab , updating "disk" root and URL fixed the issue in config/filesystems.php

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path().'/app/public',
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],

    ],

Make sure you have symlink in your public directory to do so just run.

php artisan storage:link
27 May
1 year ago

Calid left a reply on Changing The Default Location Of Storage Symlink - Laravel 5.4

I am on Linux/ Red Hat / Apache

Yes I had the app installed under sub folder domain.com/laravel, moved the index.php to domain home directory /index.php . Everything working just fine. I am trying to remove {/laravel/} from symlink so a link for avatar for example look like this :

https://domain.com/storage/users/avatar.png

pointing to

https://domain.com/laravel/storage/app/public/users/avatar.png

Calid left a reply on Changing The Default Location Of Storage Symlink - Laravel 5.4

Thanks @bashy but I am not sure I get you right, my current structure look like this

example.com example.com/laravel/ example.com/laravel/app example.com/laravel/bootstrap example.com/laravel/config . . .

I moved my index.php from ** example.com/laravel/public/ ** to ** example.com ** ...

Calid started a new conversation Changing The Default Location Of Storage Symlink - Laravel 5.4

Hello,

is there a clean way to change the default storage symlink location inside public directory. right now it is located at

http://example.com/**myfolder**/public/

so links to files look something like this:

http://example.com/myfolder/public/storage/file.ext

I placed public documents in main domain directory but can't move the public/storage my goal is to remove myfolder from the link to become

http://example.com/public/storage/file.ext

Thanks :)

26 May
1 year ago

Calid left a reply on New User Registration IP Address Laravel 5.4

Thank you guys :)

@cmgmyr spot on ... yes I forgot to set the ip column to fillable in the User model ...

Calid started a new conversation New User Registration IP Address

Hello All, My first question on Laracast :)

How can I get the user IP address and post it to users table on registration, I tried:

Use Request;

class RegisterController extends Controller { . . . . .

protected function create(array $data)
{   
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    'ip' =>  request()->ip(),                       /* Get User IP Address */
    ]);
}

}