Randy_Johnson

Member Since 3 Years Ago

Experience Points
12,350
Total
Experience

2,650 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
11
Lessons
Completed
Best Reply Awards
1
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.

  • Community Pillar

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

Level 3
12,350 XP
Jun
11
2 days ago
Activity icon

Replied to Livewire Image Upload Filename

I found this but if anyone knows a better way am all ears.

            $url = Storage::url($this->photo->store('photos'));
Activity icon

Started a new Conversation Livewire Image Upload Filename

I am trying to get the filename string. But I have no idea how to. I tried $this->photo->filename. I tried this e.g. $this->file->getClientOriginalName() of course but it just returns the original filename before the name is converted to a random string. The random string I don't mind for now, and I am in a big rush to get everything ready for the new year beginning in two months so its no fuss on my side.

Please help.

Livewire\TemporaryUploadedFile {#396 ▼
  +"disk": "local"
  #storage: Illuminate\Filesystem\FilesystemAdapter {#400 ▶}
  #path: "livewire-tmp/2k7fQRHRsxF6QAbVSjZcWoPUAjCRwi-metaMTgyNzQ3OTlfMTQ5MzUzNTc3NDA0MzYwM183OTIwNTAyOTA5NzI0MTQ5MTc2X24uanBn-.jpg"
  -test: false
  -originalName: "2k7fQRHRsxF6QAbVSjZcWoPUAjCRwi-metaMTgyNzQ3OTlfMTQ5MzUzNTc3NDA0MzYwM183OTIwNTAyOTA5NzI0MTQ5MTc2X24uanBn-.jpg"
  -mimeType: "application/octet-stream"
  -error: 0
  #hashName: null
  path: "C:\Users\Josh\AppData\Local\Temp"
  filename: "2k7fQRHRsxF6QAbVSjZcWoPUAjCRwi-metaMTgyNzQ3OTlfMTQ5MzUzNTc3NDA0MzYwM183OTIwNTAyOTA5NzI0MTQ5MTc2X24uanBn-.jpg"
  basename: "php1415.tmp"
  pathname: "C:\Users\Josh\AppData\Local\Temp\php1415.tmp"
  extension: "tmp"
  realPath: "D:\Josh\Computing\Projects\School_Tools\Register\storage\app\livewire-tmp/2k7fQRHRsxF6QAbVSjZcWoPUAjCRwi-metaMTgyNzQ3OTlfMTQ5MzUzNTc3NDA0MzYwM183OTIwNTAyOTA5NzI ▶"
  aTime: 2021-06-11 21:39:26
  mTime: 2021-06-11 21:39:26
  cTime: 2021-06-11 21:39:26
  inode: 19984723346561172
  size: 64687
  writable: false
  readable: false
  executable: false
  file: false
  dir: false
  link: false
}

Activity icon

Awarded Best Reply on Livewire Image Upload Problem

Wasn't working, dd it. Just like magic, starts working. Thanks Snape.

Activity icon

Replied to Livewire Image Upload Problem

Wasn't working, dd it. Just like magic, starts working. Thanks Snape.

Jun
09
4 days ago
Activity icon

Replied to Livewire Image Upload Problem

Ah it is crazy. I have no idea why, I have copied it line for line from the documents.

If anyone can help please.

gh repo clone JoshuaHeathcote1987/register

Inventory - addItem

New Code to show it is fully copied

    // Variables
    public $photo;


 public function addItem()
    {
        $this->validate([
            'photo' => 'image|max:10000', 
        ]);

        $this->photo->store('photos');
        // try
        // {
        //     $item = array(
        //         'name' => $this->itemName,
        //         'amount' => $this->itemAmount,
        //         'letter' => $this->itemLetter,
        //         'number' => $this->itemNumber,
        //         'img' => $this->photo, 
        //     );

          
    
        //     $this->validate([
        //         'photo' => 'image|max:10000', 
        //     ]);
    
        //     $this->photo->store('photos');

         
        // }
        // catch (\Throwable $th) 
        // {
        //     $this->message = true;
        // }
    }

    <form autocomplete="off" wire:submit.prevent="addItem">
        <div class="modal fade" id="addItemModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" wire:ignore.self>
            <div class="modal-dialog modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Add Item</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group row">
                            <div class="col-lg-4">
                                <label for="" class="col-sm-2 col-form-label text-right">Name</label>
                            </div>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" wire:model.defer="itemName">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="col-lg-4">
                                <label for="" class="col-sm-2 col-form-label text-right">Amount</label>
                            </div>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" wire:model.defer="itemAmount">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="col-lg-4">
                                <label for="" class="col-sm-2 col-form-label text-right">Section</label>
                            </div>
                            <div class="col-lg-4">
                                <select class="form-control" id="exampleFormControlSelect2" wire:model.defer="itemLetter">
                                    <option value="A">A</option>
                                    <option value="B">B</option>
                                    <option value="C">C</option>
                                </select>
                            </div>
                            <div class="col-lg-4">
                                <select class="form-control" id="exampleFormControlSelect2" wire:model.defer="itemNumber">
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
                                    <option>6</option>
                                    <option>7</option>
                                    <option>8</option>
                                    <option>9</option>
                                    <option>10</option>
                                    <option>11</option>
                                    <option>12</option>
                                    <option>13</option>
                                    <option>14</option>
                                    <option>15</option>
                                    <option>16</option>
                                    <option>17</option>
                                    <option>18</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="col-lg-4">
                                <label for="" class="col-sm-2 col-form-label text-right">Image</label>
                            </div>
                            <div class="col-lg-8">
                                <div class="custom-file">
                                    {{$photo}}
                                    <input type="file" class="custom-file-input" id="custom-file-input" wire:model="photo">
                                    <label class="custom-file-label" for="customFile">Choose file</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary" data-dismiss="modal">Save changes</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
Activity icon

Started a new Conversation Livewire Image Upload Problem

I have follow the documentation but the image doesn't seem to be placed in the file directory, it is just being placed in the livewire-tmp directory.

                                <div class="custom-file">
                                    <input type="file" class="custom-file-input" id="custom-file-input" wire:model.defer="image">
                                    <label class="custom-file-label" for="customFile">Choose file</label>
                                </div>
    public function addItem()
    {
        try
        {
            $item = array(
                'name' => $this->itemName,
                'amount' => $this->itemAmount,
                'letter' => $this->itemLetter,
                'number' => $this->itemNumber,
                'img' => $this->image, 
            );
    
            $this->validate([
                'photo' => 'image|max:10000', 
            ]);
    
            $this->photo->store('images');

            
        }
        catch (\Throwable $th) 
        {
            $this->message = true;
        }
    }
Jun
06
1 week ago
Activity icon

Replied to How To Construct An Activity Feed With TDD

add code to github and share the link and I will take a look.

Activity icon

Awarded Best Reply on Livewire Changing Var In Modal On Click

wire:ignore.self

Activity icon

Replied to Livewire Changing Var In Modal On Click

wire:ignore.self

Activity icon

Awarded Best Reply on Livewire Cannot Pass Arbitrary Value To Model

I found it, on the root div

wire:ignore.self
Activity icon

Replied to Livewire Cannot Pass Arbitrary Value To Model

I found it, on the root div

wire:ignore.self
Jun
05
1 week ago
Activity icon

Replied to Livewire Cannot Pass Arbitrary Value To Model

I have checked I am using no web add on of such.

Maybe you can see better here - https://github.com/JoshuaHeathcote1987/register

Its in the /inventory section.

If you can help it would be much appreciated.

Activity icon

Started a new Conversation Livewire Cannot Pass Arbitrary Value To Model

I have been trying to pass a value to a model, but on the passing the model displays for a short while and disappears.

I am just running a wire:click="" and if there is a variable change inside the wire click the model shows for a split second and disappears.

Ive tried many other things, such as $set. using getVarNameProperty(). My only last option is to loop the modal and have all information places that way.

Any ideas or am I out of options?

Jun
03
1 week ago
Activity icon

Started a new Conversation Livewire Changing Var In Modal On Click

I have created a structure of buttons to represent shelf's at my work, unfortunately no one has ever taken the time to ever take inventory and document this, so you can imagine. (I'm working in a kindergarten and I am the only male there.)

I am currently creating a system to fix all the problems that seem to consistently arise on a day by day, week to week basis. (Where are the leaders?)

I have created a structure to represent the shelf's that have all different materials in. I am trying to make the project as user friendly as it can possibly be. Click a shelf will show stock on that shelf, I am stuck in that I am wanting to change a variable that is presented on the modal.

The problem is, is that the model shows for a second and disappears leaving just the faded black.

Please help.

Main

<button type="button" onmouseover="mouseOver(this)" onmouseout="mouseOut(this)" class="col-lg-4 border-right border-danger text-center" style="height: 100px;" data-toggle="modal" data-target="#showContentModal" wire:click="$set('shelfNum', 1)">1</button>

Model

<h5 class="modal-title" id="exampleModalLabel">A{{$shelfNum}}</h5>

Model

<form autocomplete="off">
        <div class="modal fade" id="showContentModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header" style="background-color: #bee5eb; border-bottom: 1px solid #404040;">
                        <h5 class="modal-title" id="exampleModalLabel">A{{$shelfNum}}</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
Activity icon

Replied to Snake Case

Ahh, yeah, thanks.

Activity icon

Started a new Conversation Snake Case

Is it okay to use snake case in PHP, since I actually prefer this to Camel, or am I looking for trouble and ridicule?

Jun
02
1 week ago
Activity icon

Replied to Git Help!

SQLSTATE[HY000] [1049] Unknown database 'forge' (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

I keep getting this error, but I have organized the .env in the correct manner. My work computer is running ubuntu, and I should mention I didn't get the error when downloading the zip file. I check the chmod etc. Everything seems in order.

Activity icon

Started a new Conversation Git Help!

I made a project at home which I use as a tool at work, I uploaded the project to git and then downloaded it to my work computer through zip. I then added to the project on my home computer and now what them changes on my work computer. How would I go about doing this?

May
30
2 weeks ago
Activity icon

Awarded Best Reply on Downloaded Personal Project From Github

TURN OFF ANTI VIRUS!

Activity icon

Replied to Downloaded Personal Project From Github

TURN OFF ANTI VIRUS!

May
29
2 weeks ago
Activity icon

Started a new Conversation Downloaded Personal Project From Github

Hi, I downloaded my personal project from github so I can work on it from other locations, but I get this error when running composer install.

C:\Users\Josh\Desktop\register-main>composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 2 installs, 0 updates, 0 removals
  - Installing voku/portable-ascii (1.5.6): Extracting archive
    Install of voku/portable-ascii failed
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
    Install of hamcrest/hamcrest-php failed
    0 [>---------------------------]

  [RuntimeException]
  The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
  : ZipArchive::extractTo(C:\Users\Josh\Desktop\register-main/vendor/composer/0b154d04/voku-portable-ascii-8095367/LICENSE
  .txt): failed to open stream: Permission denied



  [ErrorException]
  ZipArchive::extractTo(C:\Users\Josh\Desktop\register-main/vendor/composer/0b154d04/voku-portable-ascii-8095367/LICENSE.t
  xt): failed to open stream: Permission denied
May
26
2 weeks ago
Activity icon

Started a new Conversation Undefined Variable: Data

I am passing data to

<?php

namespace App\Exports;

use Illuminate\Contracts\View\View;

use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

use App\Models\Student;
use App\Models\Attendance;

class AttendanceExport implements FromView, ShouldAutoSize
{

    public $data;

    public function __construct($data)
    {
        $this->data = $data;

    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function view(): View
    {
        return view('export.attendance', [
            $this->data    
        ]);
    }
}

and then in the view showing it like.

<table class="" style="">      
    <thead>
        <tr>
            @php dd($data['days']) @endphp
            <td>{{ $data['month'] }}</td>
        </tr>
        <tr>
            <td class="text-center" style="background-color: #758557;">{{ $data['name'] }}</td>
        </tr>
        <tr>
            <th style="" scope="col">#</th>
            
            @for($i=1;$i<=$data['days'];$i++)
                <th scope="col" style="background-color: #FFAEBC; border-bottom: solid 1px black;">{{substr('00' . $i, -2, 2)}}</th>
            @endfor
        </tr>

...

Can anyone see why it isn't showing anything in $data? Should be a simple problem but I just don't understand why it cannot see it. When I dd in AttendanceExport , it can see it fine.

May
20
3 weeks ago
Activity icon

Replied to Passed Back Object, But Cannot Access Variable.

So, you are saying this would be seen as a security risk.

Activity icon

Replied to Passed Back Object, But Cannot Access Variable.

Yes, this is all good, but then if I want to grab the teachers details, I would have to grab it from the database. This seems silly, when I have the teacher already, and passing it back, using dd($this->teacher) shows me that the information is there, but I cannot access, don't you think this is a little strange. Wouldn't it make sense to just access it here and now instead of querying a database for all the information?

Activity icon

Replied to Passed Back Object, But Cannot Access Variable.

That returns this array, but I just want to pick out the ID of the array, as well as other variables, later, but I cannot access that single variable.

"{"id":1,"name":"Joshua","surname":"Heathcote","created_at":"2021-05-19T06:37:58.000000Z","updated_at":"2021-05-19T06:37:58.000000Z"}"

Activity icon

Replied to Passed Back Object, But Cannot Access Variable.

dd($this->teacher['id']);
Illegal string offset 'id' 
Activity icon

Replied to Passed Back Object, But Cannot Access Variable.

    public function getStudents()
    {

        dd($this->teacher->id);
ErrorException
Trying to get property 'id' of non-object 
Activity icon

Replied to Passed Back Object, But Cannot Access Variable.

    public function getStudents()
    {

        dd($this->teacher);
Activity icon

Started a new Conversation Passed Back Object, But Cannot Access Variable.

I just want to get the id. But $this->teacher->id and $this->teacher['id'] doesn't work.

<select wire:model.defer="teacher" class="form-control" id="exampleFormControlSelect1">
                        <option></option>
                        @foreach($teachers as $teacher)
                            <option value="{{$teacher}}">{{$teacher->name}}</option>
                        @endforeach
                    </select>
dd($this->teacher);
"{"id":1,"name":"Joshua","surname":"Heathcote","created_at":"2021-05-19T06:37:58.000000Z","updated_at":"2021-05-19T06:37:58.000000Z"}"
Activity icon

Replied to Livewire Model Not Setting Variable

Hey, sorry for the stupid question. I have no idea what was wrong with it, I just copied and pasted and refreshed and it worked, checking back with CTRL Z I found it was the same. I have no idea, am guessing it was cached some how and it was running a cached version. But am not sure.

May
19
3 weeks ago
Activity icon

Started a new Conversation Livewire Model Not Setting Variable

I don't understand, this should be simple.

<div class="form-group">
                    <label for="exampleFormControlSelect1"><h3 style="font-family: 'Orelega One', cursive;">{{$month}}</h3></label>

                    <select wire:model="month" class="form-control">
                            <option value="Jan">January</option>
                    </select>

                    {{$month}}

                </div>
public $month = "February";

But selecting the January option does not change the value.

May
17
3 weeks ago
Activity icon

Started a new Conversation Laravel Certification - Is It Worth It?

I just found this exam, is it worth taking, and would it help me finding a job?

https://certification.laravel.com/

May
16
4 weeks ago
Activity icon

Started a new Conversation Data From A Collection Into A Spreadsheet

Please Help! I don't even know where to start, and figured I should get good advice before trekking down this road.

Activity icon

Replied to Last Hurdle! Problem With Livewire - Video Inside!

I fixed it! Three tutorials into Livewire and I figured it out. Should probably finish them all and get start on the Laravel after!

No idea why but the attendances collection would empty and it was as easy as reminding it.

    public function addAttendanceRecord($studentId, $day)
    {
        $teacherId = $this->teacherId;
        $studentId = $studentId;
        $day = $day;
        $month = $this->month;
        $year = $this->year;


        try {
            $attendance = Attendance::where('teacher_id', $teacherId)
                ->where('student_id', $studentId)
                ->where('day', $day)
                ->where('month', $month)
                ->where('year', $year)
                ->first();

            $attendance->delete();
        } catch (\Throwable $th) {
            $attendance = Attendance::create([
                'teacher_id' => $this->teacherId,
                'student_id' => $studentId,
                'day' => $day,
                'month' => $this->month,
                'year' => $this->year,
            ]);
        }

        $this->attendances = DB::table('attendances')
        ->where('attendances.teacher_id', '=', $this->teacherId)
        ->where('attendances.month', '=', $this->month)
        ->where('attendances.year', '=', $this->year)
        ->get();

    }
May
14
4 weeks ago
Activity icon

Started a new Conversation Last Hurdle! Problem With Livewire - Video Inside!

Ive been having an issue through the development of this app, which I just ignored until now, which is the time it can no longer be ignored.

The problem is that once the main area is filled, when clicking on ANY other input, which may not even have anything to do with that area, there is an error message displayed.

https://www.youtube.com/watch?v=5K1DGk8in9U

I took a video, and will dump the code.

            <tbody>
                @foreach($students as $student)
                    <tr>
                        <th scope="row">{{$student->name}}</th>
                        @for($i=1;$i<=$days;$i++)
                            <td>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" wire:click="addAttendanceRecord('{{$student->id}}', '{{$i}}')" 
                                    
                                        @foreach($attendances as $attendance)
                                            @if($student->id == $attendance->student_id && $attendance->day == $i)
                                                checked
                                            @endif
                                        @endforeach
                                    
                                    >
                                <div>
                            </td>
                        @endfor
                    </tr>  
                @endforeach
            </tbody>
Activity icon

Replied to ID Does Not Exist On Collection

Well that saved a lot of time. Thanks guys! Just so you know, I just do this as a hobby to stop myself doing drugs.

Activity icon

Replied to ID Does Not Exist On Collection

$student = DB::table('students') ->where('name', '=', $student->name) ->where('surname', '=', $student->surname) ->get();

Am guessing that this is getting a collection, even though only one is being returned, it is still seen as a collection.

Activity icon

Replied to ID Does Not Exist On Collection

Okay, I think its time I just watch the tutorials.

Activity icon

Started a new Conversation ID Does Not Exist On Collection

In my code I am creating a new student, and I then have to create an attendance for the student as its created:

    public function addStudent()
    {
        $name = $this->studentName;
        $surname = $this->studentSurname;
        $student = new Student;
        $student->name = $name;
        $student->surname = $surname;
        $student->save();

        $student = DB::table('students')
            ->where('name', '=', $student->name)
            ->where('surname', '=', $student->surname)
            ->get();

        $attendance = new Attendance;
        $attendance->teacher_id = $this->teacherId;
        $attendance->student_id = $student->id;						<------ Here
        $attendance->day = $this->day;
        $attendance->month = $this->month;
        $attendance->year = $this->year;

        $this->studentName = null;
        $this->studentSurname = null;
    }

The problem is that on this line $attendance->student_id = $student->id; it is giving me the error of:

Property [id] does not exist on this collection instance. 

But checking the data that is stored shows me:

Illuminate\Support\Collection {#1255 ▼
  #items: array:1 [▼
    0 => {#1098 ▼
      +"id": 17
      +"name": "fdfasdf"
      +"surname": "dasdfadsfs"
      +"created_at": "2021-05-14 19:27:47"
      +"updated_at": "2021-05-14 19:27:47"
    }
  ]
}

And my student table is clearly showing that all have id's. So I have no idea how I am to access the $student->id.

+----+--------------+--------------+---------------------+---------------------+
| id | name         | surname      | created_at          | updated_at          |
+----+--------------+--------------+---------------------+---------------------+
|  1 | Bailee       | Goldner      | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  2 | Guy          | Dickens      | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  3 | Delia        | Waelchi      | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  4 | Cheyenne     | Kris         | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  5 | Brennan      | Schneider    | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  6 | Lucinda      | O'Hara       | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  7 | Ulices       | Sauer        | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  8 | Kattie       | Kilback      | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
|  9 | Ted          | Bradtke      | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
| 10 | Ernest       | Greenholt    | 2021-05-14 19:12:51 | 2021-05-14 19:12:51 |
| 11 | Johnny       | Wall         | 2021-05-14 19:14:18 | 2021-05-14 19:14:18 |
| 12 | dfasfdsaf    | dfadsf       | 2021-05-14 19:18:23 | 2021-05-14 19:18:23 |
| 13 | dfasdff      | dafasdf      | 2021-05-14 19:20:21 | 2021-05-14 19:20:21 |
| 14 | dfadfads     | fdsafdasfdsf | 2021-05-14 19:20:59 | 2021-05-14 19:20:59 |
| 15 | fadsfadsafds | fdsfasdfsf   | 2021-05-14 19:21:26 | 2021-05-14 19:21:26 |
+----+--------------+--------------+---------------------+---------------------+
May
13
1 month ago
Activity icon

Started a new Conversation Database Diagram

Hi, I am creating a website but I am not quite sure if I have the database design correctly.

https://ibb.co/44n9tCv

class Attendance extends Model
{
    use HasFactory;

    public function classroom()
    {
        return $this->hasOne(Classroom::class, 'classroom_id', 'id');
    }
}
class Classroom extends Model
{
    use HasFactory;

    public function student()
    {
        return $this->hasMany(Student::class, 'student_id', 'id');
    }

    public function teacher()
    {
        return $this->hasMany(Teacher::class, 'teacher_id', 'id');
    }
}
class Student extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'surname',
    ];

    public function classroom()
    {
        return $this->hasOne(Classroom::class, 'student_id');
    }
}
class Teacher extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'surname',
    ];

    public function classroom()
    {
        return $this->hasOne(Classroom::class, 'teacher_id');
    }
}

I am also trying this:

        $this->students = DB::table('students')
            ->join('classrooms', function ($join) {
                $join->on('classrooms.student_id', '=', 'students.id')
                ->where('classroom.teacher_id', '=', $this->teacherId);
            })->get();

        dd($this->students);

But I am getting the error of:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'classroom.teacher_id' in 'on clause' (SQL: select * from `students` inner join `classrooms` on `classrooms`.`student_id` = `students`.`id` and `classroom`.`teacher_id` = 10) 

I must add its important that I just use query builder, Eloquent is too much magic for me.

Activity icon

Replied to DB Eloquent Help

Dammit, I just spent the last four hours coming up with this.

        $data = Student::with('attendance')->whereHas('attendance', function ($query) {
            $query->where('teacher_id', $this->teacherId);
        })->get();

Please do you know any good tutorials on this stuff. This seems to be an area where I always get stuck.

Activity icon

Started a new Conversation DB Eloquent Help

I have asked help earlier and got this

$this->attendances = Student::whereHas('attendance', function ($query) {
            $query->where('teacher_id', $this->teacherId);
        })->get();

Which is perfect but I also need the information from the attendance table which linked to the student.

mysql> select name, surname from students; +---------+---------+ | name | surname | +---------+---------+ | Johan | Reilly | | Burley | Toy | | Grant | Leannon | | Kaci | Brown | | Westley | Bayer | | Vernon | Little | | Ayden | Hintz | | Hillard | Kovacek | | Rupert | Dach | | Edmund | Pollich | +---------+---------+

+----+------------+------------+-----+---------+------+ | id | student_id | teacher_id | day | month | year | +----+------------+------------+-----+---------+------+ | 1 | 6 | 2 | 4 | January | 2021 | | 2 | 5 | 5 | 4 | January | 2021 | | 3 | 9 | 7 | 3 | January | 2021 | | 4 | 7 | 2 | 7 | January | 2021 | | 5 | 2 | 6 | 7 | January | 2021 | | 6 | 8 | 1 | 6 | January | 2021 | | 7 | 5 | 2 | 8 | January | 2021 | | 8 | 8 | 7 | 7 | January | 2021 | | 9 | 4 | 8 | 1 | January | 2021 | | 10 | 4 | 9 | 4 | January | 2021 | +----+------------+------------+-----+---------+------+

Basically, I need the student name, as well as the information from attendance of day and month.

I assumed I would use a join for such a thing, and that I have gone down the wrong route with where.

Activity icon

Started a new Conversation Where Clause Error

        $this->attendances = Attendance::where(
            ['teacher_id', '=', $this->teacherId], 
            ['month', '=', $this->month]
        )->get();
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `attendances` where (`0` = teacher_id and `1` = = and `2` = 1)) 
+----+------------+------------+-----+---------+------+
| id | student_id | teacher_id | day | month   | year |
+----+------------+------------+-----+---------+------+
|  1 |          6 |          2 |   4 | January | 2021 |
|  2 |          5 |          5 |   4 | January | 2021 |
|  3 |          9 |          7 |   3 | January | 2021 |
|  4 |          7 |          2 |   7 | January | 2021 |
|  5 |          2 |          6 |   7 | January | 2021 |
|  6 |          8 |          1 |   6 | January | 2021 |
|  7 |          5 |          2 |   8 | January | 2021 |
|  8 |          8 |          7 |   7 | January | 2021 |
|  9 |          4 |          8 |   1 | January | 2021 |
| 10 |          4 |          9 |   4 | January | 2021 |
+----+------------+------------+-----+---------+------+
Activity icon

Replied to Livewire Only Passing Value To A Variable On Second Click

Just a guess, but do you have anything on the blade side, such as defer or lazy load?

May
12
1 month ago
Activity icon

Replied to DB Querying! Dedrater Ma I

Perfect. Do you have any good resources where I can learn more of this stuff, because my knowledge is really lacking.

Activity icon

Started a new Conversation DB Querying! Dedrater Ma I

Hi, I am currently working on a project where I am having trouble just linking somethings together through the relationships. Now, as I can imagine I have done most things correctly and I am just stuck on the final hurdle. But we shall soon find out.

I just want to grab the students who are currently linked to the teacher that is being used, the teacher is selected from a drop down box, giving the $this->teacherId.

I have three tables, teacher, student, attendance, attendance linking the teacher and student together.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Attendance extends Model
{
    use HasFactory;

    public function teacher()
    {
        return $this->hasOne(Teacher::class, 'teacher_id', 'id');
    }

    public function student()
    {
        return $this->hasOne(Student::class, 'student_id', 'id');
    }
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Student extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'surname',
    ];

    public function attendance()
    {
        return $this->hasMany(Attendance::class, 'student_id');
    }
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Teacher extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'surname',
    ];

    public function attendance()
    {
        return $this->hasMany(Attendance::class, 'teacher_id');
    }
}
$this->students = Attendance::where('teacher_id', '=', $this->teacherId)->get();
        
        dd($this->students);
Activity icon

Started a new Conversation Help! Register Idea, Unable To Implement!

https://ibb.co/KqtxMQD

Using Laravel Livewire

Teacher - select the teacher of the class Month - select the month of intended Year - select the year of the intended

Below is the register table where all information of their attendance will be kept, the only problem is is that I have no idea on how to do it without making it hugely complicated.

Here is what I have now:

@foreach($students as $student)
                    <tr>
                        <th scope="row">{{$student->name}}</th>
                        
                        @for($i=1;$i<=$days;$i++)
                            <td>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" wire:click="addAttendanceDate('{{$student->id}}', '{{$i}}')">
                                </div>
                            </td>
                        @endfor 
                    </tr>
                @endforeach
    public function addAttendanceDate($studentId, $day)
    {
        $attendance = new Attendance;
        $attendance->student_id = $studentId;
        $attendance->teacher_id = $this->teacherId;
        $attendance->day = $day;
        $attendance->month = $this->month;
        $attendance->year = $this->year;
        $attendance->save();
    }

Now I can add it into the db table, but now its just figuring how to get it back out.

I guess I could use something like:

public function populateTable($teacher, $month, $year)
{
	$attendance = Attendance::where($teacher = $teacher and $month = month and $year = year);

	
}

Okay... Ill go down this route which I have mentioned and see where it will take me. But my question is, is this the right road, is there an easier way.

May
01
1 month ago
Activity icon

Replied to Livewire HTML Select Passing Para Problem

Amazing the paths you go down, due to one slight mistake. Thanks again!