jay_gorio

jay_gorio

Member Since 3 Years Ago

Experience Points 8,340
Experience Level 2

1,660 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 60
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

13 Apr
2 months ago
11 Apr
2 months ago

jay_gorio started a new conversation How To Fetch Users Who Does Not Have Reports For 6 Consecutive Months

I'm developing a report system, and I want to fetch users who did not report for six (6) consecutive months. How do I achieve this?

I've tried the code below but I'm not getting the desired output. There is also a problem. Let's say the date interval is 12 months. How can I determine if there is no report for 6 consecutive months?

$dateStart = '2018-10-31';
$dateEnd = '2019-03-31';

$intervals = Carbon::parse($dateStart)->diffInMonths($dateEnd);

$users = $users->whereDoesntHave('reports', function($query) use($intervals) {

    for ($i = 5; $i >= 0; $i--) { 
                
        $firstMonth = Carbon::parse($dateEnd)->subMonthsNoOverflow($intervals);

        $query->where('date', '>=', $firstMonth->format('Y-m-d'))->where('date', '<=', $dateEnd);
    }

});
25 Apr
1 year ago

jay_gorio left a reply on How To Validate If Sum Of Values Are Equal In Validation

@Vilfago Okay then. Sure, how can I contact you then?

jay_gorio left a reply on How To Validate If Sum Of Values Are Equal In Validation

@Vilfago Thanks. I am planning to change my database design, that's why I am reading a lot of articles and I read this http://filipmatthew.com/technology/database-schema-of-double-entry-accounting-module/

As an accountant, do you think I can follow that database design? It seems a good one.

jay_gorio left a reply on How To Validate If Sum Of Values Are Equal In Validation

@Vilfago Thanks. Yeah that's why I chose to have a conversation with you since you are an Accountant.

By the way. Do I need opening balance at my account and debit/credit column?

23 Apr
1 year ago

jay_gorio left a reply on How To Validate If Sum Of Values Are Equal In Validation

@Vilfago Opening balance.

e.g Account id: 1, name: BPI Cash, //BPI is a Bank balance: 100, 000, code: 1015, type_id: 1, // this will be asset subaccount_id: 1, // Cash in Bank

The check no would be for the Cash disbursement Journal

Journal id: 1, type: cash-disbursement, ...

I updated my table and added the sales tax. Yup I'll just remove the increment id on account_journal and make both the foreign key as primary.

jay_gorio left a reply on How To Validate If Sum Of Values Are Equal In Validation

@Vilfago Okay I got your point. It is a good approach. I'll be implementing that soon.

Can you check my tables to see if I am doing the right way of implementing accounting system. What I did is, I have a journals table and accounts table. I also have a pivot table which is the postings (account_journal).

The first step on my implementation is to create a journal then I will be attaching the journal_id and account_id on the postings table (account_journal). Is my approach correct?

Here is my tables

    Schema::create('accounts', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('type_id')->unsigned();
        $table->string('code');
        $table->string('name');
        $table->string('description')->nullable();
        $table->text('note')->nullable();
        $table->double('balance')->nullable();
        $table->boolean('with_subaccount')->default(false);
        $table->integer('subaccount_id')->nullable();

        $table->timestamp('date')->nullable();


        $table->foreign('type_id')
            ->references('id')
            ->on('types')
            ->onDelete('cascade');

        $table->timestamps();

    });

    Schema::create('journals', function (Blueprint $table) {
        $table->increments('id');
        $table->string('payee');

        $table->string('transaction_no')->unique();
        $table->string('voucher_no');
        $table->string('remarks');
        $table->string('check_no')->unique();
        $table->string('type');

        $table->boolean('isPosted')->default(0);
        $table->timestamp('transaction_date');

        $table->timestamps();
    });

    Schema::create('account_journal', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('account_id')->unsigned();
        $table->integer('journal_id')->unsigned();
        $table->double('amount');

        $table->foreign('account_id')
            ->references('id')
            ->on('accounts')
            ->onDelete('cascade');

        $table->foreign('journal_id')
            ->references('id')
            ->on('journals')
            ->onDelete('cascade');

        $table->timestamps();
    });

For now I will not be including the currency first. But thanks for the advice.

jay_gorio left a reply on How To Validate If Sum Of Values Are Equal In Validation

@Vilfago Thanks for your answer. I think I have a wrong database design then. I will just change my debit and credit column to amount then. But what if I want to stop user from inputting unbalance account from the form. How can I achieve this in validation?

jay_gorio started a new conversation How To Validate If Sum Of Values Are Equal In Validation

I have this accounting project where I need to validate if debit and credit are equal before saving to the database.

e.g

accounts: [ {

    id: 1,
    account_id: 1,
    debit:  1000
},
{
    id: 2,
    account_id: 5,
    credit: 1500
},
{
    id: 3,
    account_id: 8,
    debit: 500
}

]

By the way I am using axios and lodash.

axios.post('/api/journals', {

accounts : map(this.accounts, function(account) {

    account_id: account.account_id,
    debit: account.debit,
    credit: account.credit
})

}

Can anyone suggest how to implement this validation rule.

30 Jan
2 years ago

jay_gorio left a reply on Laravel Mix Not Working Properly

@laracast I think did is a common issue even in windows platform and MacOS. Can you please check on this. Thank you.

jay_gorio started a new conversation Laravel Mix Not Working Properly

When running npm run dev to compile my assets it does not display tables but rather displays this - https://s28.postimg.org/yzt6ar24d/npm_run_dev.png .Also when running npm run watch it seems it does not reflect changes when saving my javascript files. https://s24.postimg.org/5tqmvr7j9/npm_watch.png

07 Oct
2 years ago

jay_gorio left a reply on Where Are You All From?

Baguio, Philippines

jay_gorio started a new conversation Why Laravel 5.3 Phpunit So Slow When Using Faker

I am using sqlite for my test and using phpunit. I configure created another .env.testing and defined connection as sqlite. I also configure phpunit.xml and using DB_CONNECTION as sqlite. Also I used faker for my test as shown below. However it took so long (more than 3 minutes) for the test to be completed. I created also a new laravel 5.3 project but with the same testing result. When using laravel 5.2, my tests are extremely fast. However in 5.3 it seems there is something wrong, especially using faker. Did anyone experience this in laravel 5.3? Or am I missing something?

https://s17.postimg.org/cwjnz6567/result_of_test.png

use Faker\Factory as Faker; use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions;

class SeriesTest extends TestCase { use DatabaseTransactions;

protected $fake;

public function setUp()
{
    parent::setUp();

    $this->fake = Faker::create();
}

/** @test */
public function it_display_all_series()
{
    $series = factory(App\Series::class, 2)->create();

    $this->get('/api/v1/series');

    foreach($series as $series){
        $this->seeJson([        
            'title' => $series->title,
            'description' => $series->description,              
            'image_cover' => $series->image_cover,
            'slug' => $series->slug
        ]);
    }

    $this->assertResponseOk();
}

Here is my model factory setup

08 Sep
2 years ago

jay_gorio left a reply on How To Place Vue Variable Inside A Laravel Bracket

@usama.ashraf Thanks but I am fetching my data using the Algolia API and it seems it's not possible to define a custom attribute for the Course model. Are there any solution apart from you suggestion?

jay_gorio started a new conversation How To Place Vue Variable Inside A Laravel Bracket

I am having problem displaying the vue variable output when using it together with laravel. Below is my code.

In the above code I make used of @{{course.id}} inside the route in the a element. However it seems it is not working. Can anyone help me on this.

30 Jun
2 years ago

jay_gorio started a new conversation Cannot Login With Custom Authentication Connecting To Another Api

We are working on two laravel projects one for front end laravel and for backend api. I followed tutorials on connecting this two projects but make use of guzzlehttp. However I am getting undefined index password. I already dd the user['data'] in getUsers method and gettign the correct password. Can any one help me on this.

ApiUserProvider

<?php

namespace App\Auth;

use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
use Illuminate\Http\Request;

use GuzzleHttp\Client;

class ApiUserProvider implements UserProvider
{
    
    public function retrieveByCredentials(array $credentials)
    {
        $user = $this->getUserByUsername($credentials['username']);

        return $this->getApiUser($user);
    }

    public function retrieveById($identifier)
    {
        $user = $this->getUserById($identifier);

        return $this->getApiUser($user);
    }

    public function validateCredentials(UserContract $user, array $credentials)
    {
        return $user->getAuthPassword() == bcrypt($credentials['password']);
    }

    protected function getApiUser($user)
    {
        if ($user !== null) {
            return new ApiUser($user);
        }
    }

    protected function getUsers()
    {
        $client = new Client(['base_uri' => 'http://127.0.0.1:80/api.kourse/public/api/v1/']);
        
        $response1 = $client->request('POST', 'oauth/access_token', [
            'form_params' => [
                'client_id' => 'id1',
                'client_secret' => 'secret1',
                'grant_type' => 'password',
                'username' => '[email protected]',
                'password' => 'password'
            ]
        ]);
        

        $location = json_decode($response1->getBody(), true);

        $token = $location['access_token'];

        // Send a request to https://foo.com/api/test
        $response2 = $client->request('GET', 'users/self', [
            'headers' => [
                'Authorization' => 'Bearer '. $token
            ]
        ]);
        
        $user = json_decode($response2->getBody(), true);
        return $user['data'];
    }

    protected function getUserById($id)
    {
        $user = [];

        if($this->getUsers()['email'] == $id){
            $user['id'] = $id;
        }

        dd($user);
        return $user ?: null;
    }

    protected function getUserByUsername($username)
    {
         $user = [];

        
        if($this->getUsers()['email']  == $username){
            $user['email'] = $username; 
        }
       
        return $user ?: null;
    }

    // The methods below need to be defined because of the Authenticatable contract
    // but need no implementation for 'Auth::attempt' to work and can be implemented
    // if you need their functionality
    public function retrieveByToken($identifier, $token) { }
    public function updateRememberToken(UserContract $user, $token) { }

}

ApiUser

namespace App\Auth;

use Illuminate\Auth\GenericUser;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;

class ApiUser extends GenericUser implements UserContract
{


    public function getAuthIdentifier()
    {
        return $this->attributes['id'];
    }
}

UserController

public function login(Request $request)
{
    $email = $request->email;
    $password = bcrypt($request->password);

    if (Auth::attempt(['username' => $email, 'password' => $password])) {
        return "hello";
    } 
}
26 Jun
3 years ago

jay_gorio started a new conversation How To Fetch GroupBy Using Eloquent

I want to fetch all subjects that belongs to each semester. However I cannot find ways to do that. For example in my view I want to fetch subjects that are offered in fist first-sem. Also display below subjects offered in first second-sem. Here is my code.

StudentCourseController public function show($studentId, $courseId) { $student = Student::findOrFail($studentId); $course = Course::with(['curriculum.subjects' => function($query){ $query->get()->groupBy('sem_offered')->toArray(); }])->findOrFail($courseId);

    return view('students.show',compact('student','course'));
}

Curriculum Model

class Curriculum extends Model
{
    protected $fillable = ['name', 'description'];
    
    public function course()
    {
        return $this->hasOne(Course::class);
    }

    public function subjects()
    {
        return $this->belongsToMany(Subject::class)->withPivot('sem_offered','grade','prerequisite');
    }
}

Subject Model

class Subject extends Model
{
    
    public function curricula()
    {
        return $this->belongsToMany(Curriculum::class)->withPivot('sem_offered','grade');
    }
}

Course Model class Course extends Model { protected $fillable = ['curriculum_id', 'name' ,'description'];

    public function curriculum()
    {
        return $this->belongsTo(Curriculum::class);
    }

}

Here is my view @foreach($course->curriculum->subjects as $subject)

    <tr>
        <td>{{ $subject->subject_code }}</td>
        <td>{{ $subject->subject_description }}</td>
        <td>{{ $subject->lecture_units }}</td>
        <td>{{ $subject->lab_units }}</td>
        <td></td>
        <td>{{ $subject->pivot->grade }}</td>
    </tr>

@endforeach
22 Jun
3 years ago

jay_gorio left a reply on Cannot Upload File Using Guzzle And Send To Laravel API

@GwynBleidd I already change it to file_name but thesame result .

jay_gorio left a reply on Cannot Upload File Using Guzzle And Send To Laravel API

Can anyone please help me on this? I really need to solve this.

jay_gorio started a new conversation Cannot Upload File Using Guzzle And Send To Laravel API

I have two laravel projects, one for API and one for front end. What I want to achieve is to send the uploaded file on my front end and send it to my API using guzzlehttp6. Here's my code.

FrontEnd Laravel:

public function store(Request $request, $module_id)
{
    $videos = $request->file('file');
    // $name = time().$videos->getClientOriginalName();
    // $path = ('videos');
    // $videoFinal = $videos->move($path, $name);

    $file_name = fopen($videos, 'r');
    $client = new Client(['base_uri' => 'http://localhost/api.kourse/public/api/v1/']);

    try{
        $response = $client->request('POST', 'modules/'.$module_id.'/videos',[
            
            'fie_name' => $file_name
           
        ]);

    }catch(ClientException $e){
        return $e->getResponse();
    }
    

}

When returning the $videos im getting the path of the file.

Here's my API

public function store(VideoRequest $request, $moduleId)
{

    $module = Module::find($moduleId);

    if( !$module )
    {
        return response()->json([

            'message'   => 'Module does not exist',
            'code'      => 404
        ],404);
    }

    $file = $request->file('file_name');
    $name = time(). $file->getClientOriginalName();
    $path = '/videos';
    $file->move(public_path().$path, $name);
    Video::create([
        
        'file_name' => $name,
        'file_path' => $path.$name,
        'module_id' => $module->id
    ]);

    return response()->json([

        'message'   => 'Successfully created and assgin video to this module'
    ],200);
}

What Iam getting is that :

{message: {file_name: ["The file name field is required."]}, code: 422}
code
:
422

as defined in my VideoRequest.

Can anyone help me on this.

05 Jun
3 years ago

jay_gorio started a new conversation Nested V-for (vue Js) When Fetching Pivot Table In Laravel

When fetching pivot table in laravel is much easier. However, when using the v-for in vue js is much harder. Can anyone help me how to convert my code into vue js. I have this model, that contains below code:

public function index()
{
    $courses = Course::with('sectionSubjects','sectionSubjects.courses',
                 'sectionSubjects.section', 
                 'sectionSubjects.subject')->get();

    return $courses;
}

In my view,

@foreach($courses as $course) @foreach($course->sectionSubjects as $c) {{ $course->name }} {{ $c->subject->subject_code }} {{ $c->pivot->semester }} {{ $c->pivot->year }}

            <button type="button"
                    class="btn btn-danger btn-xs" 
                    v-on:click="deleteSectionSubject($index,sectionSubject)">

                    <i class="fa fa-times" aria-hidden="true"></i>
            </button>

            </a>
        </td>
    </tr>
    @endforeach
@endforeach

Can anyone suggest how to achieve this in vue js.

01 Jun
3 years ago

jay_gorio left a reply on Nested Eager Loading With Constraint Not Working

Btw, I'm getting undefined index : first first-sem.

jay_gorio started a new conversation Nested Eager Loading With Constraint Not Working

I am having hard time using nested with with constraint. Can someone help me to group subjects based on the what semester it will be offered.

MyController public function show($id) { $student = Student::with(['course', 'course.curriculum', 'course.curriculum.subjects' => function($query){ $query->groupBy('sem_offered'); }])->findOrFail($id);

        return view('students.show', compact('student'));
    }

show.index

@foreach($student->course->curriculum->subjects['first first-sem'] as $subject)
<tr>
    <td>{{ $subject->subject_code }}</td>
    <td>{{ $subject->subject_description }}</td>
    <td>{{ $subject->units }}</td>
    <td></td>
    <td>98</td>
</tr>
@endforeach

jay_gorio left a reply on Divide Collection Into Parts On Laravel

@willvincent I solved it since it is returning array. What I need to do is just to call the array with this student['first semester']; Btw thanks.

jay_gorio left a reply on Divide Collection Into Parts On Laravel

@willvincent Okay So here's my table

Course Code Descriptive Title Units Prerequisites Grade
    <tbody>
        @foreach($student->course->curriculum->subjects as $subject)
        <tr>
            <td>{{ $subject->subject_code }}</td>
            <td>{{ $subject->subject_description }}</td>
            <td>{{ $subject->units }}</td>
            <td></td>
            <td>98</td>
        </tr>
        @endforeach
    </tbody>
</table>

<table class="table table-bordered">
    <thead>
        <tr>
            <th>Course Code</th>
            <th>Descriptive Title</th>
            <th>Units</th>
            <th>Prerequisites</th>
            <th>Grade</th>
        </tr>
    </thead>

    <tbody>
        @foreach($student->course->curriculum->subjects as $subject)
        <tr>
            <td>{{ $subject->subject_code }}</td>
            <td>{{ $subject->subject_description }}</td>
            <td>{{ $subject->units }}</td>
            <td></td>
            <td>98</td>
        </tr>
        @endforeach
    </tbody>
</table>

Let's say for example in my StudentController i make use of the groupBy (correct my code if their's a correction)

public function show($id)

{ $student = Student::with('course', 'course.curriculum', 'course.curriculum.subjects')->findOrFail($id);

return view('students.show', compact('student'));

}

Now what will the next thing to do if I want to display on the first table - base the code on top all the subjects that are for first semester and also with the second table that would display the subjects related to second semester?

jay_gorio left a reply on Divide Collection Into Parts On Laravel

@willvincent When using dd() im getting the categorized value bases on their categories. But I cannot figure our how to implement that on my view.

jay_gorio left a reply on Divide Collection Into Parts On Laravel

@willvincent Okay after using the groupBy how will I categorized the data and display those data on the table based on their categories?

jay_gorio left a reply on Divide Collection Into Parts On Laravel

@xdimension Yeah I think group by is what Im looking at.

jay_gorio left a reply on Divide Collection Into Parts On Laravel

@mhankins Okay thanks for the advice

jay_gorio left a reply on Divide Collection Into Parts On Laravel

Okay I found solution by using the splice();

jay_gorio left a reply on Divide Collection Into Parts On Laravel

@willvincent Thanks. But how will I implement it on view using table?

jay_gorio started a new conversation Divide Collection Into Parts On Laravel

I have this curriculum type of data that should be displayed and unequally divided. See this image

What I want is to achieve something like thisthis

Here's my code:

StudentController.php

public function show($id)
{
    $student = Student::with('course', 'course.curriculum', 'course.curriculum.subjects')->findOrFail($id);

    return view('students.show', compact('student'));
}

show.blade.php

<div class="panel-body">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Course Code</th>
                <th>Descriptive Title</th>
                <th>Units</th>
                <th>Prerequisites</th>
                <th>Grade</th>
            </tr>
        </thead>

        <tbody>
            @foreach($student->course->curriculum->subjects as $subject)
            <tr>
                <td>{{ $subject->subject_code }}</td>
                <td>{{ $subject->subject_description }}</td>
                <td>{{ $subject->units }}</td>
                <td></td>
                <td>98</td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>
28 May
3 years ago

jay_gorio left a reply on Get Url Param Vue Js And Laravel (really I Need Your Help)

@sayful Are you sure with this var studentID = {{ $id }}? this will not work right. And why do I need to return a view form. What I want is to fetch an api .

jay_gorio left a reply on Get Url Param Vue Js And Laravel (really I Need Your Help)

@thomaskim Saw your question before we have the same concern. But when I used the $route.params.id Im getting undefined params. Can you help me on this.

27 May
3 years ago

jay_gorio started a new conversation Get Url Param Vue Js And Laravel

I am having problem fetching the uri of a nested resource when using vue js. See below code.

ReservationController.php

public function index($id)
    {   

        $student = Student::with(['sectionSubjects','sectionSubjects.section', 
                    'sectionSubjects.subject'])->findOrFail($id);

        return $student->sectionSubjects;   
      
    }

all.js

methods:{

        fetchSubjects: function(){
            var self = this;
            this.$http({
                url: 'http://localhost:8000/reservation/id/student',
                method: 'GET'
            }).then(function (reservations){
                this.$set('reservations', reservations.data);
                console.log('success');
                
            }, function (response){
                console.log('failed');
            });
        }
    }

The problem here is, getting the value of the id of this url http://localhost:8000/reservation/id/student. Is there a way to get the id of the parameter of the index() method? Also here's my route list http://imgur.com/8MWaCpO

jay_gorio left a reply on How To Get Uri Address Of A Nested Resources Using Vue Js

Can I make used of regex in my all.js?

jay_gorio started a new conversation How To Get Uri Address Of A Nested Resources Using Vue Js

I am having problem fetching the uri of a nested resource when using vue js. See below code.

ReservationController.php

public function index($id)
    {   

        $student = Student::with(['sectionSubjects','sectionSubjects.section', 
                    'sectionSubjects.subject'])->findOrFail($id);

        return $student->sectionSubjects;   
      
    }

all.js

methods:{

        fetchSubjects: function(){
            var self = this;
            this.$http({
                url: 'http://localhost:8000/reservation/id/student',
                method: 'GET'
            }).then(function (reservations){
                this.$set('reservations', reservations.data);
                console.log('success');
                
            }, function (response){
                console.log('failed');
            });
        }
    }

The problem here is, getting the value of the id of this url http://localhost:8000/reservation/id/student. Is there a way to get the id of the parameter of the index() method? Also here's my route list http://imgur.com/8MWaCpO

jay_gorio left a reply on Get Id Parameter Of One Method And Accessed By Another Method In Controllers

@jusahah87 I read the nested resource but I cannot get how to implement it, since I will only use one parameter which is the student_id

jay_gorio left a reply on Get Id Parameter Of One Method And Accessed By Another Method In Controllers

@jusahah87 Well thank you for your response. Yeah that's why I make used of injection. Thanks for the link

26 May
3 years ago

jay_gorio started a new conversation Get Id Parameter Of One Method And Accessed By Another Method In Controllers

I am having problems getting the value of custom create method. What I want is to get the variable $student_id and place it on my findOrFail() in the index method as shown below:

ReservationController.php

public function index()
{

    $student = Student::with(['sectionSubjects','sectionSubjects.section', 
                'sectionSubjects.subject'])->findOrFail(1); //$student_id

    return $student->sectionSubjects;    
     
}

public function create($id)
{
    $student_id = $id;

    $subjects = Subject::with('sections')->get();
 
    return view('reservation.form',compact('subjects','student_id'));
}

Here's my route:

Route::resource('student', 'StudentController');
Route::resource('reservation', 'ReservationController', ['except' => ['create','show'] ]);

Route::get('reservation/{id}/create', 
    ['as' => 'reservation.create', 'uses' => '[email protected]'
]);

I have this form.blade.php that when a user click on a student it will be redirected to the custom create method in the ReservationController as seen below:

<div class="list-group ">
@inject('student', 'App\Http\Controllers\StudentController')
    @foreach($student->index() as $s)
        <div class="list-group-item">
            <h4 class="list-group-item-heading">
                {{ $s->first_name }} {{ $s->middle_name }} {{ $s->last_name }}</i>
            </h4>
            <h5>
               ID No.: {{ $s->id_no }}</i>
            </h5>
           
           <a href="{{ route('student.edit', $s->id) }}" class="btn btn-xs btn-primary">Edit Info</a>
           
           <a href="{{ route('reservation.create', $s->id ) }}" 
              class="btn btn-xs btn-danger">
              Enroll
            </a> 
        
        </div>
    @endforeach
  
</div>

Now in the index method in the ReservationController, I want to fetch only values that are related to that $student_id. However, I cannot figure out to achieve this. Can anyone suggest ways to solve this?

25 May
3 years ago

jay_gorio left a reply on How To Display Fetch Values Upon Clicking A Button Using Vue And Laravel

@deringer Okay I used vue-devtools and I got this result. imgur.com/FUxWd2f It turns out that when pushing the response.data to reservations the format is array. As you can see in the link, the 2:Array is not an object. How can I solved this now?

jay_gorio left a reply on Getting Undefined Values When Adding A Table Data Using Vue Js

Upon using veu-devtool it turns out that I am pushing an array instead of object. Here' s the link of the image. http://imgur.com/FUxWd2f

24 May
3 years ago

jay_gorio left a reply on Getting Undefined Values When Adding A Table Data Using Vue Js

By the way I have this errors in my console.log

Error when evaluating expression "reservation.section.section_code": TypeError: Cannot read property 'section_code' of undefined

Error when evaluating expression "reservation.subject.subject_code": TypeError: Cannot read property 'subject_code' of undefined

Error when evaluating expression "reservation.subject.subject_description": TypeError: Cannot read property 'subject_description' of undefined

Error when evaluating expression "reservation.subject.units": TypeError: Cannot read property 'units' of undefined

jay_gorio left a reply on Getting Undefined Values When Adding A Table Data Using Vue Js

@clay Thanks. I did your suggestion. But I cannot see values upon clicking the button. I need to refresh the page to update the table.

jay_gorio started a new conversation Getting Undefined Values When Adding A Table Data Using Vue Js

I have this project that when a user clicks on a button the data should be displayed on a table. However, I am using a table as seen here http://i.stack.imgur.com/HW4rE.jpg. What I want is that when a user clicks on the add button on the enrollment form table, it should displayed on the added subjects table without the need of refreshing the page. The problem is that I am using a table and I cannot make use of the v-model to bind the values.

So here's my form.blade.php

Enrollment Form table

<table class="table table-bordered">
  <tr>
    <th>Section</th>
    <th>Subject Code</th>
    <th>Descriptive Title</th>
    <th>Schedule</th>
    <th>No. of Units</th>
    <th>Room</th>
    <th>Action</th>
  </tr>
  <body>
    <input type="hidden" name="student_id" value="{{ $student_id }}">
    @foreach($subjects as $subject)
      @foreach($subject->sections as $section)
      <tr>
        <td>{{ $section->section_code }}</td>
        <td>{{ $subject->subject_code }}</td>
        <td>{{ $subject->subject_description }}</td>
        <td>{{ $section->pivot->schedule }}</td>
        <td>{{ $subject->units }}</td>
        <td>{{ $section->pivot->room_no }}</td>
        <td>
          <button 
              v-on:click="addSubject( {{ $section->pivot->id}}, {{ $student_id}} )" 
              class="btn btn-xs btn-primary">Add
          </button>

          <button class="btn btn-xs btn-info">Edit</button>
        </td>
      </tr>
      @endforeach
    @endforeach
  </body>
</table>

AddedSubjects Table

<table class="table table-bordered">     
    <tr>
      <th>Section Code</th>
      <th>Subject Code</th>
      <th>Descriptive Title</th>
      <th>Schedule</th>
      <th>No. of Units</th>
      <th>Room</th>
      <th>Action</th>
    </tr>
    
    <body>

    <tr v-for="reservation in reservations">
      <td>@{{ reservation.section.section_code }}</td>
      <td>@{{ reservation.subject.subject_code }}</td>
      <td>@{{ reservation.subject.subject_description }}</td>
      <td>@{{ reservation.schedule }}</td>
      <td>@{{ reservation.subject.units }}</td>
      <td>@{{ reservation.room_no }}</td>
      <td>
        <button class="btn btn-xs btn-danger">Delete</button>
      </td>
    </tr>

    </body>
</table>

And here's my all.js

new Vue({
el: '#app-layout',

data: {

    reservations: []

},
ready: function(){
    this.fetchSubjects();
},
methods:{

    fetchSubjects: function(){
        this.$http({
            url: 'http://localhost:8000/reservation',
            method: 'GET'
        }).then(function (reservations){
            this.$set('reservations', reservations.data);
            console.log('success');
        }, function (response){
            console.log('failed');
        });
    },

    addSubject: function(section,subject,student_id){
        var self = this;
        this.$http({
            url: 'http://localhost:8000/reservation',   
            data: { sectionSubjectId: section.pivot.id, studentId: student_id },
            method: 'POST'
        }).then(function(response) {
            self.$set('reservations', response.data);   
            console.log(response);
            self.reservations.push(response.data);
        },function (response){
            console.log('failed');
        });
    }
  }
});

Here's my ReservationController

class ReservationController extends Controller {

public function index()
{
    $student = Student::with(['sectionSubjects','sectionSubjects.section', 'sectionSubjects.subject'])->find(1);

    return $student->sectionSubjects;    
     
}

public function create($id)
{
    $student_id = $id;

    $subjects = Subject::with('sections')->get();
 
    return view('reservation.form',compact('subjects','student_id'));
}

public function store(Request $request)
{
    
    $subject = SectionSubject::findOrFail($request->sectionSubjectId);

    $student = Student::with(['sectionSubjects','sectionSubjects.section', 'sectionSubjects.subject'])->findOrFail($request->studentId);

    $subject->assignStudents($student);

    return $student->sectionSubjects;

}

}

Can anyone suggets me on how to solve this problem, without the need of refreshing the page.

jay_gorio left a reply on How To Display Fetch Values Upon Clicking A Button Using Vue And Laravel

@deringer Still not working. Still getting this - [Vue warn]: Error when evaluating expression "reservation.section.section_code": TypeError: Cannot read property 'section_code' of undefined.

19 May
3 years ago

jay_gorio left a reply on How To Display Fetch Values Upon Clicking A Button Using Vue And Laravel

@deringer I tried to return the values of $subject->assignStudents($student); and getting the values of the student info.

jay_gorio left a reply on How To Display Fetch Values Upon Clicking A Button Using Vue And Laravel

@deringer here's the console.log of my response in the addsubject : Object {request: Object, data: "", status: 200, statusText: "OK", ok: true}