Paschal

Founder & Web Developer at ArioniX Studios

Member Since 3 Years Ago

Lagos

Experience Points
5,980
Total
Experience

4,020 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
6
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 2
5,980 XP
Dec
27
1 year ago
Activity icon

Replied to SyntaxError: Unexpected Token < In JSON At Position 0 At JSON.parse (<anonymous>) At XMLHttpRequest.c

This happened to me a lot and it was a real headache finding the cause. Check your controllers and make sure there is no leading space in the .php file before the <?php tag.

Activity icon

Replied to Angular 4/5 And Laravel 5.5 XSRF-TOKEN

Put your token in your meta tag of your header (If that doesn't exist yet). Configure your ajax to always pick the token from header so you don't have to include it in every ajax result.

Aug
27
2 years ago
Activity icon

Replied to Eloquent Result Issues

I know it's very very very bad programming though, I never intended to use it for production, I was only trying out long polling.

This was what I was trying to do:

  1. GET request from AJAX that stays open until a new row is found and returned.
  2. If no new row, keep calling, apparently it will fail after 30s because of MAX_EXECUTION. (Since Apache uses a new thread for a request, its worth trying out on a local machine so I thought).

My confusion was this:

//Updates the Polling table and mark the unseen as seen. 
    Pooling::whereSeen(false)->update(['seen' => true]);
    //After doing this, $res becomes empty. 

After this query, $res returns empty;

I found a better solution using socket though but curiosity, I was wondering why $res is empty;

You mentioned this, apparently, that was what I skipped and the problem.

assuming then, a row appears, you return a response which then bubbles up from all the nested index calls, resetting the database at each return.

Thanks for your reply.

Aug
25
2 years ago
Activity icon

Started a new conversation Eloquent Result Issues

I am trying to test out basic long pooling technique. I setup Ajax that uses GET request to fetch row of results from database that has not been read.

Problem is after mass updating and flagging a row as seen I.e setting seen column to true, it returns an empty response. However, if I omit the mass updating, it returns available results.

Here is my controller code.

use App\Pooling; 

function index(){
    
    $res = Pooling::whereSeen(false)->get();

    if(count($res) < 1){

        //Recursion: Calls this function again if no results. 
        $this->index();
    }
    
    //Updates the Polling table and mark the unseen as seen. 
    Pooling::whereSeen(false)->update(['seen' => true]);
    //After doing this, $res becomes empty. 

    //Returns empty result
    return response()->json( $res ); 
}
Aug
18
2 years ago
Activity icon

Replied to Cannot Use More Than One Request ?

@lukaisailovic I think it's clashing with another. You don't need to rename, do this instead

use App\Http\Requests\LoginRequest as UserLoginRequest; 
Activity icon

Replied to Dynamic Router For Database Driven Website

@jeremyhart That will be a challenge but it's solvable... Peep @sagar.jagtap response, you might have to explode parameters and get them as array then do your magic.

I can't really say if it's efficient but it might solve the problem.

Aug
17
2 years ago
Activity icon

Replied to Blade Syntax Rendering From Mysql Query

No. It should render correctly. That is strange, try and dump it in controller before rendering the view and ensure the config value is set.

Activity icon

Replied to Populating Multiple Relations From The Same Query Result

Use Eloquent Relationships. Read more about it in Laravel docs.

That is the solution you are looking for.

Activity icon

Replied to Authentication Credentials From Another Table

You'll have to do manual authentication and override the default Laravel login...

Mind you that method above doesn't do the check, it just returns the login credentials from the request.

After running your check, you can use the attempt method on the Auth facade to try to log a user in.

Step by step what you'll do.

  1. Override the default login, simply open your Auth\LoginController and add a method login.
  2. Get the passed credentials from the request.
  3. Check if the email exists for a user in the database.
  4. DO YOUR ADDITIONAL CHECK.
  5. Attempt to log the user in.
  6. If failed, do something, if passed do something else.

Sample Code

//This method in your login controller will override laravel's login. 

public function login(Request $request) {

    $credentials = $this->credentials($request); 

    // Get the user login
    $login = $credentials[$this->username()];

    //Check if that login exists
    if(\App\User::where($this->username(), $login)->count() > 0 ) {

        //Login exists, 
        //Do your additional check 

        if(YOUR ADDITIONAL CHECK IS PASSED) {

            //Try to login the user
            if(Auth::attempt($credentials) {

                //Login successful, do something here
            }
            else{

                //Login not successful, do something else instead 
            }
        }
        else{

            //Your additional check did not pass 
            //Do something 
        }
    }
    else{
    
        //The provided credentials does not exist for any user in database 
        //Do something
    }
}

Above code is not production ready, mix of code & gibberish but gives an insight on how to handle such a problem.

Activity icon

Replied to Is This Possible With Wordpress?

You are asking this question in the wrong place.

Stack overflow should do.

http://stackoverflow.com

Activity icon

Replied to Blade Syntax Rendering From Mysql Query

What do you mean by blade variable? Do note that you can't initialize or assign variables with blade, you can use the traditional way.

<?php $myImage = 'Some data'; ?>

Also note this might be a poor idea and instead be moved to your controller.

Activity icon

Replied to Database Structure

Good to go then @KillerCore

Activity icon

Replied to Working With Multiple Tables

@king_eke Good for you then. Hope you've considered expansion, what if you need to add another user type later in future? you'll have to do Database work all over again, whereas, with the solution I provided, you won't need all that, you just keep writing the code as if it was created from inception.

Activity icon

Replied to Database Structure

Well rollback and dd this

dd( $street->neighborhood );

See what it returns. If it does not return a Neighborhood collection, check that the relationship was defined well, including the foreign and local key.

Aug
16
2 years ago
Activity icon

Replied to Database Structure

Well that's pretty strange. This should work:

$street->neighborhood->user->name //does not work

Dump the following in your controller and see if it returns a User model.

dd( $street->neighborhood->user );
Activity icon

Replied to Adding Service Providers In Config/app.php

I don't think that is possible with Laravel, if it was possible, packages won't be telling us to add the providers in the config/app.php providers array. And also you don't want to edit the file at runtime via code... BAD BAD BAD.

Check out Laravel 5.5 with auto-loading providers... Although specially crafted for Package Development, you can bend your module-driven style to achieve something of that nature.

Activity icon

Replied to Cannot Use More Than One Request ?

Check the class name and make sure it matches the file name. Also, make sure it is namespaced correctly.

namespace App\Http\Requests;
Activity icon

Replied to Database Structure

Well, there you have it.

What do you mean by 'anything deeper', how deep are you trying to go?

The below should work too so far you set your relationship right and they contain data, else if it's null, you'll get the Trying to get property of non-object error.

$street->neighborhood->area->city->name;
Activity icon

Replied to Adding Service Providers In Config/app.php

It is possible. Make sure you understand PSR-4 & autoloading...

Say the service provider is located in Admin\AdminServiceProvider.php

The App\\ is already PSR-4'd in composer.json file, so loading that will be simple as:

App\Admin\AdminServiceProvider::class

Same thing goes for Customer

Activity icon

Replied to Dynamic Router For Database Driven Website

Well, you have to be really really creative with your programming to get this to work as is... VERY VERY CREATIVE. The biggest challenge will be in the controller.

Now here comes the problem. The /cat1/sub-ca2/sub-cat3/ part, will it always be like this? Will every route have a cat1, sub-cat2, sub-cat3?

If YES then it's pretty easy.

First thing is to understand routing, optional route parameters etc.

I'll do this.

Routes.php

Route::get('/{category}/{sub-cat2}/{sub-cat3}/{page}', '[email protected]');

RouteController.php

function index($category, $subCat2, $subCat3, $page){
    
    $productsData = collect(); //You'll do your logic here with the categories to get the products data.

    //Make sure to sanitize the $page variable since it is gotten as input from the client. SECURITY CONCERNS

    return view($page)->with($productsData);
}

If NO, you will need extra programming magic. You'll also need to explain more & better what you want to achieve to see if I can be of help.

Activity icon

Replied to Database Structure

How about the $street->neighborhood->name, does it load?

The way Model works can be tricky, did you check the relations when you dd'd and saw nothing?

Activity icon

Replied to Database Structure

Yes you can @killercore. You can just use chaining like this...

In your controller method, get the steeets

Street::get();

In your view, loop through the street variable.

@foreach ($streets as $street)
    <tr>
        <td>{{ $street->name }}</td>
        <td>{{ $street->neighborhood->area->city->id; }}</td>
        <td>{{ $street->neighborhood->name; }}</td>
        <td>{{ $street->neighborhood->user->name; }}</td>
        <td>0612345678</td>
    </tr>
@endforeach

There you go. I use objects instead of arrays.

Activity icon

Replied to Checking The Existence Of A Row.

In the model

Activity icon

Replied to How To Display Video Previews

Well it depends. Two ways...

  1. You cut it outside and upload as a mini version (Advantage: You have control as to what to show. Disadvantage: Extra storage space required)

  2. You use a video plugin package (search for one I'm sure it exists) to cut the video at run time (Advantage: Reduced storage. Disadvantage: Extra processing time at the expense of memory)

Aug
15
2 years ago
Activity icon

Replied to Checking The Existence Of A Row.

How did you define the database relationship?

Aug
14
2 years ago
Activity icon

Replied to How To Validate Foreign Key With Unique Constraint?

What is your challenge exactly?

Activity icon

Replied to Validating An Array Of Inputs In Laravel 5.0

What file is that code located? Also before the return $rules, try and break out of the code. Dump the $rules variable with dd and post the output here.

Like this: dd( $rules )

Activity icon

Replied to Laravel Tag

What do you mean by tag?

Activity icon

Replied to Checking The Existence Of A Row.

Observation 1: Optimize your code

Replace this line:

$user_id = Auth::id();
$user = User::find($user_id);

With this:

$user = Auth::user();

It will return the same result so far there is a user in session.

When you say:

... user has access to a row in the DB.

Are you talking about database access/privilege or you are talking based on the context of how your site is structured?

If it's based on how your site is structured, explain better what you are trying to achieve and what the application is all about.

Activity icon

Replied to How To Display Video Previews

This is a job for the client-side. You have to get hand-on Javascript.

Aug
13
2 years ago
Activity icon

Replied to Would It Be Simpler To Modify Auth Or Make My Own Login System For Sms Integration?

You'll have to create your own custom with for that.

Activity icon

Replied to Laravel : Where Do I Rewrite Auth() In Router.php?

Rule number 1: NEVER HACK CORE

It is bad to edit the source files.

You can override the default route in your web.php route file. Just use the same signature and point it to another controller of your choice / anonymous functions as the case may be.

NB: You must place it after the Auth::routes() statement if one exists in your route file.

If you don't want all the routes for auth provided by laravel by default, you should remove this line in web.php file in your routes folder.

Auth::routes();
Activity icon

Replied to Would It Be Simpler To Modify Auth Or Make My Own Login System For Sms Integration?

Do you need a login system with two-factor authorization via SMS? If that's what you need, check out this package I wrote a few days ago.

It has support for both Twilio & Nexmo

https://github.com/paschaldev/laravauth

Activity icon

Replied to Url In Web.php Not Working

I believe he definitely has a download folder in document root

Activity icon

Replied to Url In Web.php Not Working

@Snapey Is every request not passed through Laravel's URI Router first?

Activity icon

Replied to Laravel 5.4 - Auth Groups Session And Old() Are Empty

@Mintis it's empty. Do you use a validator? If you do, after providing wrong details, immediately after the validation login, dump the validation and see if it passed.

Activity icon

Replied to Database Structure

I would go with this approach.

  1. Create a Street table and model
  2. Create a Neighborhood table and model.
  3. Create an Area table and model.
  4. Create a City table and model.

Each of them will have a unique ID, in their migrations, they'll have this which will be their unique ID and primary key. The migrations will look like this:

//street_migration

<?php
.
.
.
Schema::create('street', function (Blueprint $table) {
    $table->increments('id');
    $table->name('name');
    $table->integer('neighborhood_id');
});

//neighborhood_migration

<?php
.
.
.
Schema::create('neighborhood', function (Blueprint $table) {
    $table->increments('id');
    $table->name('name');
    $table->integer('area_id');
    $table->integer('user_id')->unsigned();
});

//area_migration

<?php
.
.
.
Schema::create('area', function (Blueprint $table) {
    $table->increments('id');
    $table->name('name');
    $table->integer('city_id');
    $table->integer('user_id')->unsigned();
});

//city_migration

<?php
.
.
.
Schema::create('city', function (Blueprint $table) {
    $table->increments('id');
    $table->name('name');
    $table->integer('user_id')->unsigned();
});

You can as well implement foreign keys if you need one.

Now, I will proceed to add relationships in the models, I believe a Street can only belong to one Neighborhood.

So in the Street model, I have this:

<?php 

//App\Street
.
.
.

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

While in the Neighborhood, a Neighborhood can only belong to one Area but have many Street and also be assigned to a User.

<?php 
//App\Neighborhood
.
.
.

public function streets(){
    return $this->hasMany('App\Street');
}

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

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

An Area can have many Neighborhood but can only belong to one City and also be assigned to a User

So in the Area model, I have this:

<?php 
//App\Area
.
.
.
public function neighborhoods(){
    return $this->hasMany('App\Neighborhood');
}

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

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

Lastly, a City can have many Area and only belong to a User, so we have this in the City model:

<?php 
//App\City
.
.
.

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

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

Finally, for the User, we already have a user_id field for Neighborhood, City and Area and a relationship for each of them from those models. To access a User area, neighborhood or city, we add this to the User model:

<?php 
//App\User
.
.
.

public function neighborhood(){
    return $this->hasOne('App\Neighborhood');
}

public function area(){
    return $this->hasOne('App\Area');
}

public function city(){
    return $this->hasOne('App\City');
}

That, my friend is how you implement something like what you desire.

Activity icon

Replied to Url In Web.php Not Working

The output looks incomplete... Although I see app/download and download. Post the complete output

Activity icon

Replied to Laravel 5.4 - Auth Groups Session And Old() Are Empty

Your route seems to have the web middleware. Dump this variable in your login view and tell me what you get. Make sure you input the wrong details in the login form so it can generate errors.

print_r( $errors )
Aug
12
2 years ago
Activity icon

Replied to Several BelongingTo Layers

Yes. It's possible.

Relationships are data models and also query builders depending on what you need it for.

You can absolutely do something like this. A sample scenario is this your forum's post. If you have a reply table that is a relationship defined on the forumPost model. You can get the ID of the first reply to your post like this e.g

$forumPost->replies->first()->id

You just have to know how to implement relationships very well and doing it the right way. Pretty simple tho

Activity icon

Replied to What Is The Best Practices Way Of Managing Many ManyToMany Relationships In Models?

Each of them has to be explicit. Relationships in Eloquent are not magic and has to be defined by you.

This line of code is your way out or better still, get a full understanding of Relationships, understand how your database communicates and you might not have to do many relationships.

return $this->belongsToMany('App\OtherModel');
Activity icon

Replied to Url In Web.php Not Working

Post the output of route:list here let me see

Activity icon

Replied to Working With Multiple Tables

@king_eke This is how you achieve something like that.

  1. You have 1 user table
  2. You use roles and permissions to implement the lecturer / student thing. Check out this package I use [https://github.com/spatie/laravel-permission]
  3. If you want to store different data / fields as the case maybe, use a different table. You can call it user_meta, the table will contain a user_id, property and value.

I'm assuming you know about Eloquent \ Models \ Relationships. Add the UserMeta a relationship on your User model.

Now if you need to store something for a particular user, simply add the value to the user_meta like this:

<?php

use UserMeta; //The user meta model
.
.
.

$userMeta = new UserMeta;
$userMeta->user_id = $user->id;
$userMeta->property = 'course';
$userMeta->value= 'CSC 222';

//Assumption: You are trying to add a course to a lecturer user but not student. Implementing something like this is the easiest way out.
Activity icon

Replied to First Model In A Collection

Well sums it all

Activity icon

Replied to Laravel 5.4 - Auth Groups Session And Old() Are Empty

Is this route file web.php and you are sure your Laravel version is 5.4?

I recently had this issue when building a custom package and it turns out it was a problem with middlewares. My routes were not in the web middleware.

This is what you'll do, run this artisan command:

php artisan route:list

POst the output here let me see

Activity icon

Replied to Working With Multiple Tables

Why are you using two user tables instead for a single app?

Activity icon

Replied to RetrieveById Breaking Change Between Laravel 5.4.19 -> 5.4.20

Can you explain better? Finding it hard to understand the message you are trying to pass