jvbalcita

jvbalcita

Member Since 7 Months Ago

Pasay City

Experience Points
15,640
Total
Experience

4,360 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
146
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.

Level 4
15,640 XP
Jun
30
1 week ago
Activity icon

Replied to Get First Data Even There Is Multiple Query

@bugsysha I forgot to mention that this is an API. Our front end is VUE + NGINX. So we don't have to create multiple school year?

What's happening is when the first admin created the school year our public api for the enrollment form works fine. But when the 2nd admin created the school year nothing shows up on our enrollment form. So meaning only the first admin from the school database with the id of 1 can is the only one showing. What we want to happen is anyone can add school year but still show in the enrollment form correctly.

Activity icon

Started a new Conversation Get First Data Even There Is Multiple Query

Not sure if a have the right title for this issue but I have a school data that has a separate database for school year. The school data consist of the list of schools and its relationship user.

School Database

id
user_id
schl_sys_id
schl_name

School Year Database for

school_id
year_from
year_to

The school can have many school admin in this case there's 2 school admin user with the same schl_sys_id

schl_sys_id => SCHL0001

Then the first admin created the school year 2020-2021 and the 2nd admin created 2021-2022 on the same day.

the system will detect the latest creation. however what I want to achieve is regardless of who created the school year for the SCHL0001 should be the first created school year even if I'm passing the ID

Here's my code when showing the school data with the relationship with school year.

    public function show(School $school)
    {
        $database = $school->schl_sys_id;

        $school = DB::table('schools')
        ->join($database.'.school_year as school', 'school.school_id', '=', 'schools.id')
        ->where('schl_sys_id', '=', $database)
        ->limit(1)
        ->get();
    

        return SchoolResource::collection($school);
    }

This will return

id
user_id
schl_sys_id
schl_name
year_from
year_to
Jun
26
2 weeks ago
Activity icon

Replied to 500 Internal Server Error On Laravel Forge 2nd Database

@bobbybouwmann, yes all migrations work. We found the issue by changing the APP_DEBUG to true and found out that one of the controller namespace is incorrect but actually works in local. Issue resolved. :)

Activity icon

Replied to 500 Internal Server Error On Laravel Forge 2nd Database

@nexxai , yes that's the first 2 lines of our deployment script. migrations works fine on both database.

Activity icon

Replied to 500 Internal Server Error On Laravel Forge 2nd Database

@bobbybouwmann, It was actually working in our local server. It there a difference between using setConnection and DB::connection? We are using the setConnection to fetch the 2nd database. Not what's wrong with our .env file. We'll check the storage/logs.

Jun
25
2 weeks ago
Activity icon

Started a new Conversation 500 Internal Server Error On Laravel Forge 2nd Database

We're actually deploying our Laravel application now in Forge. But we are getting a 500 Internal Server Error when fetching the data from the 2nd database. We have public and private API from that database and both returns 500 error.

We tested both locally and it works fine.

Also tried using postman to access the API from the main database and it is returning the data fine. But for the 2nd database same issue.

Here's our .ENV file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=schoolname
DB_USERNAME=root
DB_PASSWORD=

DB_CONNECTION_SECOND=mysql
DB_HOST_SECOND=127.0.0.1
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=SCHL0000001
DB_USERNAME_SECOND=root
DB_PASSWORD_SECOND=

And the Database.php

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'SCHL0000001' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST_SECOND'),
            'port' => env('DB_PORT_SECOND'),
            'database' => env('DB_DATABASE_SECOND'),
            'username' => env('DB_USERNAME_SECOND'),
            'password' => env('DB_PASSWORD_SECOND'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

We are using DigitalOcean managed database. We also tried using the local database of Forge. Same issue.

Migrations work fine. We checked both database and all have records inside. Our problem is just it's not getting anything from the 2nd database.

Is there a bearing using the MYSQL 8 in DigitalOcean? We tried using MySQL 5.7

Hope someone can help us :(

Jun
21
2 weeks ago
Activity icon

Replied to Saving Post When There Is Validation Error

Wow! I never knew this was possible! Thank you @bobbybouwmann. I will never regret signing up for your book. :)

Activity icon

Replied to Saving Post When There Is Validation Error

@bobbybouwmann I'm actually testing it using postman since this is an API. Is there a difference between postman and typical form?

In regards to the validation part, I've thought about that but I'm getting the connection name from the ID that is being passed through.

	$id = $request->school_id; // From Enrollment Form
        
        $database = School::findOrFail($id)->schl_sys_id;

        $school = School::findOrFail($id)->id;
 $student->setConnection($database);

Should I just move the validation in my controller to get the connection?

Activity icon

Started a new Conversation Saving Post When There Is Validation Error

I have an enrollment form. It can post perfectly but when there is validation like unique email the ID will still increment.

For example I submitted successfully a form with no duplicate email the id will be 1 and the student number will be STUDENT001

I submitted again with duplicate and and error validation will show up. Then fixed the validation and submit again. the id will be 3 and the student number will be STUDENT003

In the database only 2 data is showing since the 2nd submission fails.

Here's my Enrollment Controller.

public function store(EnrollmentRequest $request): StudentResource
    {
        $id = $request->school_id; // From Enrollment Form
        
        $database = School::findOrFail($id)->schl_sys_id;

        $school = School::findOrFail($id)->id;
        
        $student = new Student($request->all());
        $student->setConnection($database);
        $student->school_id = $school;
      	$student->save();
	
	// Generate Student Number
        $studentID = str_pad($student->id, 5, "0", STR_PAD_LEFT);
        $schoolID = str_pad($id, 2, "0", STR_PAD_LEFT);
        $studentNumber = $schoolID . '-' . $studentID;

        Student::on($database)->where('id', $student->id)->update(['student_number' => $studentNumber, 'login_email' => $request->login_email]);
        
        return new StudentResource($student);
    }

in my validation rules I've tried the

'email' => 'required|unique:students,email,'.$this->id

And it's giving me an error that the database is not found since I have another database for enrollment form which I set in the controller.

Jun
20
2 weeks ago
Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance

Yes it works. I just removed the resource collection. Thank you :)

Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance

@michaloravec

I got it by changing it toreturn GradeLevelPublicResource::collection($gradeLevel); as per your advise.

Now I'm getting this list of data. I only have one question How can I make the pluck work to get only the list of grade levels?

{
    "data": [
        {
            "school_id": 201,
            "grade_level": "Grade 5"
        },
        {
            "school_id": 201,
            "grade_level": "Grade 6"
        },
        {
            "school_id": 201,
            "grade_level": "Grade 7"
        },
        {
            "school_id": 201,
            "grade_level": "Grade 8"
        },
        {
            "school_id": 201,
            "grade_level": "Grade 9"
        },
        {
            "school_id": 201,
            "grade_level": "Grade 10"
        }
    ]
}

Activity icon

Replied to Property [id] Does Not Exist On This Collection Instance

@michaloravec

Thank you for refactoring it.

I tried the get(); and it's giving me the same error.

If I use first(); with the same ID I query this is the result

{
    "data": {
        "id": 1,
        "school_id": 201,
        "grade_level": "Grade 5"
    }
}

I researched before and get() is almost the same solution but it's not working form me.

I wanted to show

"data": {
        "id": 1,
        "school_id": 201,
        "grade_level": "Grade 5"
    },
{
        "id": 2,
        "school_id": 201,
        "grade_level": "Grade 6"
    },
{
        "id": 3,
        "school_id": 201,
        "grade_level": "Grade 7"
    }
Activity icon

Started a new Conversation Property [id] Does Not Exist On This Collection Instance

I have a table from another database that holds Grade Levels.

I am trying to show all the grade level with the same school_id

Here's my Grade Level Controller

public function show($id)
    {
        $school = School::find($id); //find school id
        $sysID = $school->schl_sys_id; //get schl_sys_id
        $databaseName = $sysID; //pass schl_sys_id to database

        $gradeLevel = GradeLevel::on($databaseName)->where('school_id', $id)->pluck('grade_level');
        
        return new GradeLevelPublicResource($gradeLevel);
    }

I tried using pluck to get only the list of grade levels but I'm getting an error message Property [id] does not exist on this collection instance in postman.

When I use first(); it will only show one(1) data. In my database I have 6 grade levels with same school_id.

By the way the school table is on my default database that's why I set GradeLevel::on($databaseName)

Activity icon

Awarded Best Reply on Separate Roles And Permissions For Each Application

We'll actually be doing that approach.

But should we just use the laravel-permission package and have a centralized roles for all applications and just manipulate the permissions?

Jun
19
3 weeks ago
Activity icon

Replied to Separate Roles And Permissions For Each Application

We'll actually be doing that approach.

But should we just use the laravel-permission package and have a centralized roles for all applications and just manipulate the permissions?

Activity icon

Started a new Conversation Separate Roles And Permissions For Each Application

Just need helping hand if I'm doing the right thing or if there is a better approach for this in Laravel.

I have a system that will contain multiple applications and aside from the main system roles I will have another table of roles inside it.

Here's the sample overview

Main System
    -Roles
	-isAdmin
	-isMember
Application1
    -User Roles
        -isAdmin
        -isParent
        -isTeacher
        -isStudent
Application2
    -User Roles
        -isAdmin
        -isOfficial
        -isCaptain
	-isMember

Will I have problems in the future if I do this? or should I just centralize the roles for all the applications? Is there a better approach for this that is less complex?

Jun
18
3 weeks ago
Activity icon

Replied to How To Name A Group Of Array In One Post

I found the culprit. OtherFee::insert($fees); is inside the foreach. :) Thanks!

Activity icon

Replied to How To Name A Group Of Array In One Post

@michaloravec I just have one problem now. When I post this to the database It's duplicating the data. In this example I posted 3 and it is inserting 6 records in the database now.

Activity icon

Replied to How To Name A Group Of Array In One Post

you saved my life @michaloravec ! Thank you very much!

Activity icon

Started a new Conversation How To Name A Group Of Array In One Post

I am working an API response. I have a form that can submit a list of data.

Here's my GradeLevelController

public function store(Request $request)
    {
        $now = Carbon::now()->toDateTimeString(); //timestamps

        $data = [
            'grade_level' => $request->grade_level,
            'target_hc' => $request->target_hc,
            'student_ratio' => $request->student_ratio,
            'reg_fee' => $request->reg_fee,
            'tuition_fee' => $request->tuition_fee,
            'misc_fee' => $request->misc_fee,
        ];

        $gradeLevel = GradeLevel::create($data);

            if (count($request->other_charges) > 0) {
                foreach ($request->other_charges as $fee=>$v) {
                    $data[] = array(
                    'grade_level_id' => $gradeLevel->getKey(),
                    'other_charges' => $request->other_charges[$fee],
                    'amount' => $request->amount[$fee],
                    'created_at'=>$now,
                    'updated_at'=>$now
                );
                    //OtherFee::insert($data);
                }
            }

            return new OtherFeeResource($data);
}

I can insert the multiple records fine.

Here's the return I get from postman.

{
    "data": {
        "grade_level": "grade 5",
        "target_hc": "1000",
        "student_ratio": "1:50",
        "reg_fee": "4000",
        "tuition_fee": "5000",
        "misc_fee": "1000",
        "0": {
            "grade_level_id": 125,
            "other_charges": "12345",
            "amount": "123",
            "created_at": "2020-06-18 19:53:52",
            "updated_at": "2020-06-18 19:53:52"
        },
        "1": {
            "grade_level_id": 125,
            "other_charges": "123456",
            "amount": "2314",
            "created_at": "2020-06-18 19:53:52",
            "updated_at": "2020-06-18 19:53:52"
        },
        "2": {
            "grade_level_id": 125,
            "other_charges": "11",
            "amount": "11",
            "created_at": "2020-06-18 19:53:52",
            "updated_at": "2020-06-18 19:53:52"
        }
    }
}

What I want to achieve is to have a name for the array of other charges like this

{
    "data": {
        "grade_level": "grade 5",
        "target_hc": "1000",
        "student_ratio": "1:50",
        "reg_fee": "4000",
        "tuition_fee": "5000",
        "misc_fee": "1000",
	"fees": [
	{
            "grade_level_id": 125,
            "other_charges": "12345",
            "amount": "123",
            "created_at": "2020-06-18 19:53:52",
            "updated_at": "2020-06-18 19:53:52"
        },
	{
            "grade_level_id": 125,
            "other_charges": "123456",
            "amount": "2314",
            "created_at": "2020-06-18 19:53:52",
            "updated_at": "2020-06-18 19:53:52"
        },
	{
            "grade_level_id": 125,
            "other_charges": "11",
            "amount": "11",
            "created_at": "2020-06-18 19:53:52",
            "updated_at": "2020-06-18 19:53:52"
        }]
    }
}

I have tried the protected $wrap = 'fees'

but that will wrap everything the form will submit.

I also tried data['fees']and that will only return 1 array of data.

Jun
17
3 weeks ago
Activity icon

Replied to How To Get ID Of Authenticated User Relationship

Sorry for the late response.

I haven't actually tried the session since I am using API and testing it on Postman.

When I tried dd($user->applications); on post I gives me loads of html styles but the data is not there. but when I removed the applications I was able to get the list of users.

It seems that applications() is not being called or something.

can't seem to figure out where to fix this.

Jun
16
3 weeks ago
Activity icon

Replied to How To Get ID Of Authenticated User Relationship

@guybrush_threepwood It actually works with Tinker. It's pulling up a record of which is user is assigned to an application. In the solution you provided the applications() is underlined in red.

For the relationship part. I think I may have explained it incorrectly. It should only get the ID of the application where the current user is logged in. Is there a better approach for that? coz the system will have many applications and the user can have access to 1 or 2 applications.

Activity icon

Replied to How To Get ID Of Authenticated User Relationship

@guybrush_threepwood

What I'm actually want to achieve is the user can have many applications and the application can have many users.

Activity icon

Replied to How To Get ID Of Authenticated User Relationship

Hi @guybrush_threepwood ,

Yes I actually just want to return one ID related to the user and I've tried your solution but I got an error message. Trying to get property 'id' of non-object

or am I just doing the relationship wrong?

Activity icon

Started a new Conversation How To Get ID Of Authenticated User Relationship

I'm trying to get the logged in user related ID.

I have an Application, Users and Schools

Users and Application has a pivot table calls app_tags that has (application_id and user_id)

Users Model

public function applications()
    {
        return $this->belongsToMany(Application::class, 'app_tags', 'user_id', 'application_id');
    }

Applications Model

public function users()
    {
        return $this->belongsToMany(User::class, 'app_tags', 'user_id', 'application_id');
    }

Now I want to get the ID of the application related to the user. I can show it from tinker but not able to in my controller. By the way I'm using postman.

Schools Controller

public function store(Request $request)
    {
        $school = new School($request->all());

        $user = auth()->user()->id;
        $application = User::findOrFail($user)->applications;
        
        $school->user_id = $user;
        
        $school->client_id = $application->pluck('id')->toArray();
        $school->save();

        return new SchoolResource($school);
        
    }

with my controller I'm getting an error message in Postman "Array to string conversion", even if I remove the toArray I can't get the ID of the application.

Jun
14
3 weeks ago
Activity icon

Replied to Laravel - Many To Many Relationship

Hi @michaloravec,

Great! Thank you for that.

Sorry I must have clicked the best answer. I already clicked the best answer on your response awhile ago.

:)

Activity icon

Replied to How To Create New Database From A Submitted Form.

@martinbean, actually the first idea is only the admin user will input a form and then it will create a database automatically once the form is submitted. Then we figured out that we will just be the one creating the database for each application.

Activity icon

Started a new Conversation Problem Storing Multiple Data In One Form

I have a problem storing a multiple data from a single form.

I created 2 tables. GradeLevel and Other Fees

The grade level is the main table and the other fees will have multiple data that is in relation to grade level.

Here's my GradeLevelController

public function store(Request $request)
    {

        $gradeLevel = new GradeLevel;
        $gradeLevel->grade_level = $request->grade_level;
        $gradeLevel->target_hc = $request->target_hc;
        $gradeLevel->student_ratio = $request->student_ratio;
        $gradeLevel->reg_fee = $request->reg_fee;
        $gradeLevel->tuition_fee = $request->tuition_fee;
        $gradeLevel->misc_fee = $request->misc_fee;

        $gradeLevel->save();

        $now = Carbon::now()->toDateTimeString(); //timestamps
        OtherFee::insert([
            'grade_level_id' => $gradeLevel->id,
            'other_charges' => $request->other_charges,
            'amount' => $request->amount,
            'created_at' => $now,
            'updated_at' => $now]);
        
        return new GradeLevelResource($gradeLevel);
    }

The OtherFee model should be inserted multiple times if I have 2 or more other charges and amount. But when I tested it in postman only one data is inserted.

I tried to cast it but I'm getting an error "message": "Array to string conversion",

protected $casts = [
        'other_charges' => 'json',
        'amount' => 'json',
    ];
Activity icon

Replied to How To Create New Database From A Submitted Form.

@tray2 Well, end up is I will just create a manual database for each application.

I have a Main Database with users table, application table.

User table will have all the email and passwords Application table will have the application name and application_number (Application_01)

Now the problem is in I will have created database for example Application_01.

I will have a registration table for each database application

Now a public form to have the user enter basic details (firstname, middlename, lastname, etc.) once they hit the Submit button it should identify which database it should store.

I have configured my database.php to add another database.

I am passing the Application_01 as the database name to my controller.

How am going to select that database to insert the data dynamically?

Activity icon

Replied to How To Create New Database From A Submitted Form.

Hi @tray2,

Am I going to include this on my Model or Controller? Sorry I'm fairly new to this.

Thanks for your answer by the way.

Activity icon

Started a new Conversation How To Create New Database From A Submitted Form.

Hi I was wondering if there is a way that we can create a new Database based on the submitted form.

For example I submitted a form of Applications that has an Application name. That Application name will be the unique database name. ie. (APP001, APP002)

Thank you in advance.

Jun
13
3 weeks ago
Activity icon

Replied to Laravel - Many To Many Relationship

Thank you @michaloravec

That totally works for me as well as this one.

User Model

public function applications()
    {
        return $this->belongsToMany(Application::class, 'app_tags', 'user_id', 'application_id'); 
    }

Application Model

public function users()
    {
        return $this->belongsToMany(User::class, 'app_tags', 'user_id', 'application_id');
    }

Appreciate the help :)

Activity icon

Started a new Conversation Laravel - Many To Many Relationship

I would seek like out help with creating Many to Many relationships for my API.

So I have an applications table and users table.

I created a Pivot table named "app_tags" as I want to tag a user with many applications (inverse)

Here's my migration for Applications.

Schema::create('applications', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('application_name');
            $table->text('description');
            $table->timestamps();
        });

And here's for my users migration.

Schema::create('app_tags', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('application_id');
            $table->timestamps();
            
            Schema::create('users', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name');
                $table->string('email')->unique();
                $table->timestamp('email_verified_at')->nullable();
                $table->string('password');
                $table->rememberToken();
                $table->timestamps();
            });
            $table->unique(['user_id', 'application_id']);

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('application_id')->references('id')->on('applications')->onDelete('cascade');
        });

The migration went fine but when I'm trying to show all the Users applications and inverse using Tinker I get an error

>>> App\User::find(1)->applications;
Illuminate/Database/QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel7.application_user' doesn't exist (SQL: select `applications`.*, 
`application_user`.`user_id` as `pivot_user_id`, `application_user`.`application_id` as `pivot_application_id` from `applications` inner join `application_user` on `applications`.`id` = `application_user`.`application_id` where `application_user`.`user_id` = 1)' 

I've been working on this one for a long time now and can't figure out how to fix it. I'm just new to laravel and really wanted to learn more day by day. I hope you can help me.

May
01
2 months ago
Activity icon

Commented on Many To Many Relationships With Linking Tables

I am trying to add my own tables as an example but I am getting an error message when I'm trying to add employees table and an employee id to tickets table.

Create Tickets Table

        Schema::create('tickets', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('employee_id');
            $table->unsignedBigInteger('user_id');
            $table->string('type');
            $table->string('subject');
            $table->text('description');
            $table->timestamps();

            //Set up unique key
            $table->unique(['employee_id', 'user_id']);

            $table->foreign('employee_id')
            ->references('id')
            ->on('employees')
            ->onDelete('cascade');

            $table->foreign('user_id')
            ->references('id')
            ->on('users')
            ->onDelete('cascade');

Create Employees Table

Schema::create('employees', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('full_name');
            $table->string('business_unit');
            $table->string('business_segment');
            $table->timestamps();
        });

Error

 SQLSTATE[HY000]: General error: 1005 Can't create table `laravel`.`tickets` (errno: 150 "Foreign key constraint is in
correctly formed") (SQL: alter table `tickets` add constraint `tickets_employee_id_foreign` foreign key (`employee_id`)
 references `employees` (`id`) on delete cascade)


1   D:\xampp\htdocs\laravel6\vendor\laravel\framework\src\Illuminate\Database\Connection.php:464
      PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `laravel`.`tickets` (errno: 150 "Foreignkey constraint is incorrectly formed")")

What could be causing this one? I have followed the course carefully.

Apr
12
2 months ago
Activity icon

Commented on Forms, Request Types, And Routing

I am still stuck in this lesson.

I am getting an error message

Fatal error: Uncaught Exception: No route defined for this URI in D:\xampp\htdocs\php-practitioner\core\Router.php:47 Stack trace: #0 D:\xampp\htdocs\php-practitioner\index.php(7): Router->direct('php-practition...', 'GET') #1 {main} thrown in D:\xampp\htdocs\php-practitioner\core\Router.php on line 47

I already tried using a virtual host as well as just a localhost on XAMPP.

But still getting No route defined for this URI or sometimes error 404 when trying to tweak .htaccess with

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php [L]

I don't know if this is something to do with XAMPP or it's just me. I checked the codes and they are identical as followed.

Hope someone can help on this.