zafercuz

zafercuz

Member Since 4 Months Ago

Experience Points
580
Total
Experience

4,420 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
580 XP
Jan
19
1 month ago
Activity icon

Replied to Add Data To Database When User Is Logged Out By Auth::logoutOtherDevices()

I apologize if my question was confusing. I am not proficient with Laravel so I don't know how to declare events and such. However this is what I tried for adding the logout log

protected function loggedOut(Request $request)
    {
        if ($request->session()->has('compid')) {
            $compid = $request->session()->pull('compid');
            $request->session()->invalidate(); // Flush the session data and regenerate the ID.
            $query = UserLog::where('compid', $compid)
                    ->latest('login_at')
                    ->first()
                    ->update(['logout_at' => now()]);
        }
    }

I overrode loggedOut function. It did work if user manually logs out, but doesn't work if user is logged out because he/she logged in at another device.

Activity icon

Started a new Conversation Add Data To Database When User Is Logged Out By Auth::logoutOtherDevices()

In my LoginController, I overrode authenticated function and added

protected function authenticated(Request $request)
    {
        $current_date_time = Carbon::now()->toDateTimeString();
        UserLog::create([
            'compid' => $request['compid'],
            'login_at' => $current_date_time,
        ]);
        $request->session()->put('compid', $request['compid']);
        Auth::logoutOtherDevices(request('password'));
    }

When user logins I add a login log to UserLog table and add current date time to "login_at" column. How can I add a logout log when a user is logged out because his/her account has been logged in an another device?

Jan
12
1 month ago
Activity icon

Started a new Conversation Logging Out Other Devices Not Working After Overriding Login Function

I overrode the login function since I need to have the user login with their username/email. I also added invalidating session if ever they login to their account on another device. I followed Invalidating Session on other devices, added the line to authenticated function. Was there any code that was gone due to overriding the login function?

Here is my code:

    protected function authenticated()
    {
        Auth::logoutOtherDevices(request('password'));
    }

    public function login(Request $request)
    {
        $this->validate($request, [
            'login'    => 'required',
            'password' => 'required',
        ]);

        $login_type = filter_var($request->input('login'), FILTER_VALIDATE_EMAIL ) 
            ? 'email' 
            : 'username';

        $request->merge([
            $login_type => $request->input('login')
        ]);

        if (Auth::attempt($request->only($login_type, 'password'))) {
            return redirect()->intended($this->redirectPath());
        }

        return redirect()->back()
            ->withInput()
            ->withErrors([
                'login' => 'These credentials do not match our records.',
            ]);
    }
Oct
31
3 months ago
Activity icon

Replied to How To Add Middleware To "store" In Route Resources ?

How about applying it to the controller function? Like this

public function __construct()
{
    // Middleware only applied to these methods
    $this->middleware('auth', ['only' => [
        'store' // Could add bunch of more methods too
    ]]);
}
Activity icon

Replied to Increasing Max Execution Time In Production Not Working

Turned out this was caused by Nginx's configuration and not by PHP nor Laravel configuration. All I had to do was add two lines in /etc/nginx/nginx.conf in the http section

fastcgi_read_timeout 300;
proxy_read_timeout 300;

@hondnl Thanks bud, when you said timeout settings in nginx that was the clue to making this work, cheers!

Oct
30
3 months ago
Activity icon

Replied to Increasing Max Execution Time In Production Not Working

@hondnl request_terminate_timeout is commented

and in nginx.conf there is no fastcgi_read_timeout

And server is not behind a load balancer too.

This is getting somewhat annoying to solve now :(

Oct
29
3 months ago
Activity icon

Replied to Increasing Max Execution Time In Production Not Working

@hondnl Since I'm using Nginx it is said that with nginx the php.ini is loaded from the fpm folder so I tried changing it there too. Ofc after changing it, I restarted php7.2-fpm and nginx. But to no avail it still doesn't work.

Activity icon

Replied to Help With Validation Rule Exists

Thanks! Really thought that you should put in two where clauses for it to work.

Oct
28
3 months ago
Activity icon

Started a new Conversation Help With Validation Rule Exists

I'm having trouble assessing where the error is located in the code as I was putting in the Rule Exists Validation, this is authentication for the Register Part Here's the error

SQLSTATE[42S22]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'email'. (SQL: select count(*) as aggregate from [email_address] where [email] = [email protected] and ([EmailAddress] = [email protected] and [EmployeeCode] = 13070))

So I used Rule validation because I wanna validate if the user input of Employee Code and Email exists on a certain database table. Here's what I've tried so far

return Validator::make($data, [
            'hrisid' => ['required', 'digits:5', 'unique:users', 'exists:dtr.USERINFO,Badgenumber'],
            'name' => ['required', 'string', 'max:255'],
            'email' => [
                'required', 'string', 'email', 'max:255', 
                'regex:/^[a-zA-Z0-9_.+-][email protected](?:(?:[a-zA-Z0-9-]+\.)?[a-zA-Z]+\.)?(example)\.com$/i',
                Rule::exists('email_address')->where(function ($query) use($data){
                    $query->where('EmailAddress', $data['email'])->where('EmployeeCode', $data['hrisid']);
                }),
                'unique:users',
            ],
            'password' => ['required', 'string', 'min:8', 'confirmed', 'regex:/^\S{8,}$/'],
        ]

Email Address Table looks like this

EmployeeCode | EmployeeName | EmailAddress

Activity icon

Replied to Increasing Max Execution Time In Production Not Working

@douglasakula Yes I do, it's also not running on safe mode

Activity icon

Replied to Increasing Max Execution Time In Production Not Working

@sinnbeck Yes I did, also restarted nginx and recached the project.

Activity icon

Replied to Increasing Max Execution Time In Production Not Working

@douglasakula when I ran that it locates to the cli folder, I then tried changing the php.ini and restarting the php service and nginx. Also changed the setting from the fpm folder but to no avail it still persist to 1 minute.

Why does it not just execute ini_set('max_execution_time', 180);? This problem only occurs on production.

Oct
27
4 months ago
Activity icon

Started a new Conversation Increasing Max Execution Time In Production Not Working

My project needs more than 60 seconds to query thousands of data. I placed ini_set('max_execution_time', 180); just after the namescape on my main controller. It somehow increased the execution time to 3 minutes but it only works in development stage. In production stage, it limits execution time to 60 seconds even though I've placed the code.

I've tried changing the max_execution_time to 180 in php.ini, then restarted php7.2-fpm, nginx, recaching the config of the project but still didn't work.

Is this a laravel thing? or a PHP thing? Because I've already tried changing both php.ini in both cli and fpm folder and restarted php7.2-fpm and nginx service, but it still doesn't work.

Update: Turned out it also didn't work in local server on nginx, which would probably mean it's nginx that's causing this problem. Any ideas as to why? Here's what my server config looks like

server {
    listen 80;
    server_name example.com;
    #root /var/www/Project_KamotV2/public;
    root /home/steven-sama/Project_KamotV2/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

I copied this from laravel official site in deployment section in the documentation.

Oct
22
4 months ago
Activity icon

Replied to Send Mail To Real Email

I don't think he does lmao, but @bobbybouwmann thank you good sir for answering, I've just tried it and it worked perfectly.

Oct
21
4 months ago
Activity icon

Replied to Ssl Website

From what I've tried (Nginx), I just redirected them to https whenever they tried to access the non-secure (http) of the site using return 301 https://$server_name$request_uri;.

Activity icon

Started a new Conversation Send Mail To Real Email

So my company uses cPanel webmail for our company email. I've created an email that will serve as the username to use in laravel's .env file. I've been wondering how to actually send a mail to their account? This is for the authentication part where they need to verify their email addresses, and for testing purposes I am gonna use my own company email, and yes I also have a domain

I have tried mailtrap for testing purposes on local environment but now I want to do it to a real account. Can I implement it the way I implemented for mailtrap? Or should I use an API like mailgun to do it?

Activity icon

Replied to What To Learn First Laravel 5.8 Or 6 ?

I'd recommend going with the new version, there will be slight modifications that you'll have to make, for an example on implementing Authentication. That's why there's a documentation right?

Oct
18
4 months ago
Activity icon

Replied to Auth Registration How To Validate If Data Does Not Exist In Database

I'm so dumb, just solved it right now. Just used exists in validator rules

Activity icon

Started a new Conversation Auth Registration How To Validate If Data Does Not Exist In Database

So I have the laravel authentication and I made changes to the register validator function. I added some line of codes that will fetch the data from the database in which it will compare if that passed data from the registration blade view exists in the users database. Which then I created a return redirect containing the error message. But it produces this error

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

Is there any way to also include my created error message to the Validator::make? Here's my created code

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use App\Branch;
use App\UserInfo;
use Config;
use DB;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    public function showRegistrationForm()
    {
        $branchModel = new Branch;
        $branchModel->setConnection('branch');
        $branch = $branchModel->orderBy('bname', 'asc')->get();

        return view('auth.register', compact('branch'));
    }

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

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

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        $config = Config::get('database.connections.dtr');
        $config['database'] = "dtr_" . $data['branch'];
        config()->set('database.connections.dtr', $config);
        DB::purge('dtr');

        $exists = collect();

        DB::connection('dtr')->table('USERINFO')->select('Badgenumber')
            ->orderBy('USERINFO.USERID', 'asc')
            ->chunk(50, function ($users) use ($data, $exists) {
                foreach ($users as $user) {
                    if ($user->Badgenumber == $data['hrisid']) {
                        $exists->push(1); // push 1 if account exists in the database
                        return false;
                    }
                }
            });

        if (count($exists) == 0) { // 0 = not exist, 1 = exist
            return back()->with('error', 'HRIS ID does not exist in the database');
        }

        return Validator::make($data, [
            'hrisid' => ['required', 'digits:5', 'unique:users'],
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ], [
            'hrisid.required' => 'The HRIS ID field is required.',
            'hrisid.digits' => 'The HRIS ID field must be exactly 5 digits.',
            'hrisid.unique' => 'This HRIS ID has already been taken.',
            'name.required' => 'The Name field is required.',
            'name.string' => 'The Name field must be a string.',
            'name.max' => 'The Name field must not exceed 255 characters.',
            'email.required' => 'The Email is required.',
            'email.string' => 'The Email field must be a string.',
            'email.email' => 'The Email field needs to have a valid format.',
            'email.max' => 'The Email field must not exceed 255 characters.',
            'email.unique' => 'This Email is already taken.',
            'password.required' => 'The Password field is required.',
            'password.string' => 'The Password field must be a string.',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'hrisid' => $data['hrisid'],
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}