jay_gorio

jay_gorio

Member Since 3 Years Ago

Experience Points
8,630
Total
Experience

1,370 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-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
8,630 XP
Oct
07
1 week ago
Activity icon

Started a new conversation Double Entry Accounts For Payment Of Tuition Fees

A student has total tuition fee of 8,000. The student paid 3,000 as a down payment and the journal entry is:

Cash 3,000
AR   5,000
     Tuition Fee  8,000

But what if the student will pay 3,500 for the next payment, what would be the journal entry? Is this correct?

Cash 3,500
AR   4,500
     Tuition Fee  8,000
Jul
15
3 months ago
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

The problem with this, is that it will fetch all children not related to parent. But it definitely flatten the collection

Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

I just used your suggestion I am getting unknown method for values().

Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

Yes it return as a Collection. I made use of all the option you have given. since the And the pluck accepts the array as a paramter. But it gives me null output for each item. (See code below) But when passing only one parameter (e.g. name) It gives me result.

Collection {#295
  #items: array:6 [
    0 => null
    1 => null
    2 => null
    3 => null
    4 => null
    5 => null
  ]
}
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

Here is the code.

$parent = $parent->with('descendants')->find($parent->id);

dd($parent->pluck(['name', 'address', 'contact_no', 'id']));
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

This is the error.

exception: "ErrorException"
file: "C:\laragon\www\gawisorg\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php"
line: 1047
message: "stripos() expects parameter 1 to be string, array given"
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

Based on the laravel 5.8 documentation the pluck only takes string as its first parameter

    /**
     * Get an array with the values of a given key.
     *
     * @param  string  $value
     * @param  string|null  $key
     * @return \Illuminate\Support\Collection
     */
    public function pluck($value, $key = null)
    {
        return $this->toBase()->pluck($value, $key);
    }
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

@mstrauss Yes this works. But it is only limited with one column of table.

[
   {
      'name': 'Parent',
      'children': [
         {
             'name': 'First Child',
             'address': 'lorem ipsum',
             'contact_no': '92390',
             'children': [
                {
                    'name': 'First Descendant',
                    'address': 'lorem ipsum',
                    'contact_no': '92390',
                    'children': [
                        {
                            'name': 'Descendant Child',
                            'address': 'lorem ipsum',
                            'contact_no': '92390',
                            'children': [
                                {
                                   'name': 'Last Descendant',
                                   'address': '',
                                   'contact_no': '',
                                   'children': []
                                }
                            ]

                        }
                    ]
                }
             ]
         }
      ]
   }
]

Desired Output


    [
        {
            'name': 'Parent',
            'address': 'lorem ipsum',
            'contact_no': '92390'
        },
        {
            'name': 'First Child',
            'address': 'lorem ipsum',
                 'contact_no': '92390'
        },
        {
            'name': 'First Descendant',
            'address': 'lorem ipsum',
                 'contact_no': '92390',
        },
        {
            'name': 'Descendant Child',
            'address': 'lorem ipsum',
                 'contact_no': '92390',
        },
        {
            'name': 'Last Descendant' ,
            'address': '',
                 'contact_no': '',
        }
                
    ]

Activity icon

Started a new conversation Flatten Laravel Nested Relationship (parent To Descendants)

I have a parent children relationship on my model. What I want is to flatten all those collection including all those descendants of parent.

[
   {
      'name': 'Parent',
      'children': [
         {
             'name': 'First Child',
             'children': [
                {
                    'name': 'First Descendant',
                    'children': [
                        {
                            'name': 'Descendant Child',
                            'children': [
                                {
                                   'name': 'Last Descendant',
                                   'children': []
                                }
                            ]

                        }
                    ]
                }
             ]
         }
      ]
   }
]


I tried the code below. However it only displays the second depth of children. It does not display the next children of the collection.

User.php
public function parent()
{
    return $this->belongsTo(User::class, 'id', 'parent_id');
}

public function children()
{

    return $this->hasMany(User::class,'parent_id', 'id');
}

public function descendants()
{
    return $this->children()->with('descendants');
}

UsersController.php

public function index()
{
    $parent = User::find(1);

    $parent->with('descendants')->find($parent->id);

    $descendants = $this->traverseTree($parent->descendants);

    return response($descendants);
}

protected function traverseTree($subtree)
{
    $descendants = collect([]);

    foreach ($subtree->descendants as $descendant) {
            
       $descendants->push($descendant);

       if($descendant->descendants instanceof Collection) {

          foreach ($descendant->descendants as $node) {
                    
             $this->traverseTree($node);

             $descendants->push($node);
          }
       }
   }

   return $descendants;
}

Desired Output

[
    {
        'name': 'Parent'
    },
    {
        'name': 'First Child'
    },
    {
        'name': 'First Descendant'
    },
    {
        'name': 'Descendant Child'
    },
    {
        'name': 'Last Descendant' 
    }
            
]

I am looking forward for your help.

Jul
09
3 months ago
Activity icon

Replied to How To Place Node On Specific Position(left/right) Using Laravel-nestedset

Thank you for your response. That is why I like the package it has a lot of convenience. However, based on your answer and the documentation itself, user has no control of manually assigning the node position. Anyways thank your for the reference.

Jul
06
3 months ago
Activity icon

Replied to How To Construct A Binary Tree?

Thanks for your reply. Yeah that's the limitation of the package. Thank you for your suggestions. I am creating a multi level marketing (binary) and it seems I cannot find solution on how to implement its feature. Do you have any suggestion on how to implement this.

Jul
05
3 months ago
Activity icon

Started a new conversation How To Construct A Binary Tree?

How can we build a binary tree?

For example if the left and right child is empty find the next left empty child and append there?

Is that possible using lazychaser/laravel-nestedset package?

Activity icon

Started a new conversation How To Place Node On Specific Position(left/right) Using Laravel-nestedset

I am using the package laravel-nestedset for my multi level marketing(binary) system. However I cannot figure it out how to append the node to specific position.

Let's say for example:

$parent = User::find(1);
$child = User::create(['name' => 'Child', 'username' => 'child1']);
$parent->appendNode($child);

The output will be:

{
        id:1,
        name: 'Parent',
        parent_id: null,
        _lft: 1,
        _rgt:4,
        'username': 'parent1',
        'children: [
            {
                id:2,
                name : 'Child',
                username: 'child1',
                _lft: 2,
                _rgt: 3,
                parent_id: 1
            }
        ]
}

How do I know if the node is positioned on left or right? And what if I only want to fetch the children of parent based on left position?

Apr
13
6 months ago
Activity icon

Replied to How To Fetch Users Who Does Not Have Reports For 6 Consecutive Months

@JOHNBRAUN - Thanks.Got your logic. Already working.

Apr
11
6 months ago
Activity icon

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);
    }

});
Apr
25
1 year ago
Activity icon

Replied to 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.

Activity icon

Replied to 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?

Apr
23
1 year ago
Activity icon

Replied to How To Validate If Sum Of Values Are Equal In Validation

@Vilfago Opening balance.

    Account
 id: 1,
     name: BPI Cash, //BPI is a Bank
     balance: 100000,
     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.

Activity icon

Replied to 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.

Activity icon

Replied to 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?

Activity icon

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

postings: [
    {

        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', {

    postings : 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.

Jan
30
2 years ago
Activity icon

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

Oct
07
3 years ago
Activity icon

Replied to Where Are You All From?

Baguio, Philippines

Activity icon

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

$factory->define(App\User::class, function (Faker\Generator $faker) {
        static $password;

        return [
            'name' => $faker->name,
            'email' => $faker->unique()->safeEmail,
            'password' => $password ?: $password = bcrypt('secret'),
            'remember_token' => str_random(10),
        ];
    });

    $factory->define(App\Series::class, function (Faker\Generator $faker) {
        
        $title = $faker->sentence;

        return [
            'user_id' => factory(App\User::class)->create()->id,
            'title' => $title,
            'description' => $faker->paragraph,
            'image_cover' => $faker->image($dir = '/tmp', $width = 640, $height = 480),
            'slug' => str_slug($title)
        ];
    }); 
Sep
08
3 years ago
Activity icon

Replied to 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?

Activity icon

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.

     <input type="text" 
               class="form-control search-bar__input" 
               placeholder="Search Courses, Interests, Schools or Institutions" 
               autocomplete="on" 
               autofocus="on"
               v-model="query"
               v-on:keyup="search">
        <ul class="list-group">
            <li class="list-group-item" v-for="course in courses">
                <a href="{{ route( 'courses.show', @{{course.id}} ) }}">@{{ course.title }}</a>
            </li>
        </ul> 

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.

Jun
30
3 years ago
Activity icon

Replied to Cannot Login With Custom Authentication Connecting To Another Api

Can someone please help me on this.

Activity icon

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";
    } 
}
Jun
26
3 years ago
Activity icon

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
Jun
22
3 years ago
Activity icon

Replied to Cannot Upload File Using Guzzle And Send To Laravel API

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

Activity icon

Replied to Cannot Upload File Using Guzzle And Send To Laravel API

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

Activity icon

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 guzzlehttp 6. 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',[
            
            'file_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.

Jun
05
3 years ago
Activity icon

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)
    <tr>
        <td>{{ $course->name }}</td>
        <td>{{ $c->subject->subject_code }}</td>
        <td>{{ $c->pivot->semester }}</td>
        <td>{{ $c->pivot->year }}</td>
        <td>
            <a href="" 
                class="btn btn-info btn-xs">
                <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
            </a>

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

Jun
01
3 years ago
Activity icon

Replied to Nested Eager Loading With Constraint Not Working

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

Activity icon

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
Activity icon

Replied to 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.

Activity icon

Replied to Divide Collection Into Parts On Laravel

@willvincent Okay So here's my table

<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>

<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?

Activity icon

Replied to 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.

Activity icon

Replied to 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?

Activity icon

Replied to Divide Collection Into Parts On Laravel

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

Activity icon

Replied to Divide Collection Into Parts On Laravel

@mhankins Okay thanks for the advice

Activity icon

Replied to Divide Collection Into Parts On Laravel

Okay I found solution by using the splice();

Activity icon

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>
May
28
3 years ago
Activity icon

Replied to 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 .

Activity icon

Replied to 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.

May
27
3 years ago
Activity icon

Started a new conversation Get Url Param Vue Js And Laravel (really I Need Your Help)

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

Activity icon

Replied to How To Get Uri Address Of A Nested Resources Using Vue Js

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

Activity icon

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

Activity icon

Replied to 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

May
26
3 years ago
Activity icon

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?