Paschal

Member Since 2 Years Ago

Lagos

Founder & Web Developer at ArioniX Studios

Experience Points 5,880
Experience Level 2

4,120 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.

27 Dec
1 year ago

Paschal left a reply on 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 back sure there is no leading space in the .php file before the <?php tag.

Paschal left a reply on 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.

27 Aug
1 year ago

Paschal left a reply on 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 at 30s because of MAX_EXECUTION. (Since Apache uses a new thread for a request, its worth trying out on a local machine.

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.

25 Aug
1 year ago

Paschal 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 ); 
18 Aug
1 year ago

Paschal left a reply on 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\LoginRequests as UserLoginRequest; 

Paschal left a reply on 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.

17 Aug
1 year ago

Paschal left a reply on 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.

Paschal left a reply on 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.

Paschal left a reply on 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 userbin database 
        //Do something
    }
}

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

Paschal left a reply on Is This Possible With Wordpress?

You are asking this question in the wrong place.

Stack overflow should do.

http://stackoverflow.com

Paschal left a reply on 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.

Paschal left a reply on Database Structure

Good to go then @KillerCore

Paschal left a reply on 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.

Paschal left a reply on 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.

16 Aug
1 year ago

Paschal left a reply on 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 );

Paschal left a reply on 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 that 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 in that nature.

Paschal left a reply on Cannot Use More Than One Request ?

Check the class name and make sure it matches the file name.

Paschal left a reply on 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.

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

Paschal left a reply on 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

Same thing goes for Customer

Paschal left a reply on 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.

Paschal left a reply on 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?

Paschal left a reply on 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.

Paschal left a reply on 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.

Paschal left a reply on 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)

Paschal left a reply on Database Structure

Yes you can @killercore

15 Aug
1 year ago

Paschal left a reply on Checking The Existence Of A Row.

How did you define the database relationship?

14 Aug
1 year ago

Paschal left a reply on Cannot Post Data To Mysql Using Ajax In Laravel 5.4. SyntaxError: Unexpected Token < In JSON At Position 0 At Parse (<anonymous>) At Qb (https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js:4:10192) At A (https://ajax.googleapis.com/ajax/libs/

As @mleppala noted, try and dump and inspect the data you are sending.

Add this to your $.ajax body and inspect the console to see what you are sending.

beforeSend: function(){
    console.log( this.data );
}

Paschal left a reply on How To Validate Foreign Key With Unique Constraint?

What is your challenge exactly?

Paschal left a reply on 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 )

Paschal left a reply on Laravel Tag

What do you mean by tag?

Paschal left a reply on 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.

Paschal left a reply on How To Display Video Previews

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

13 Aug
1 year ago

Paschal left a reply on 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.

Paschal left a reply on 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 they case may be.

Paschal left a reply on 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.

https://github.com/paschaldev/laravauth

Paschal left a reply on Url In Web.php Not Working

I believe he definitely has a download folder in document root

Paschal left a reply on Url In Web.php Not Working

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

Paschal left a reply on 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.

Paschal left a reply on 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.

Paschal left a reply on Url In Web.php Not Working

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

Paschal left a reply on 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

dd( $errors )
12 Aug
1 year ago

Paschal left a reply on Several BelongingTo Layers

Yes. Iis 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

Paschal left a reply on 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');

Paschal left a reply on Url In Web.php Not Working

Post the output of route:list here let me see

Paschal left a reply on 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.