myke2424

myke2424

Member Since 1 Year Ago

Experience Points
9,160
Total
Experience

840 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
67
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 2
9,160 XP
Feb
12
3 months ago
Activity icon

Replied to POST 500 Internal Server Error AJAX POST Request

Ooops didn't mean to select you as Best Answer.

I named the route 'search' so it should work

Activity icon

Started a new Conversation POST 500 Internal Server Error AJAX POST Request

I'm getting a (Internal Server Error) 500 POST Error when I click my submit button. I'm not sure what's wrong with my AJAX Request.

Here's my code:

Ajax:

 $(document).ready(function(){

          load_data('');

          function load_data(query = ''){
          
          $.ajaxSetup({
          headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
         }
        })

          $.ajax({
              url:"{{ route('search') }}",
              method:"POST",
              data:{query:query},
              dataType:"json",
              success: function(data) {
                console.log('success')
              }, 
              error: function (data) {
              console.log('Error');
            }  
            });
          }; 

          $('#search').click(function(){
            var query = $('#query').val();
            load_data(query);
        });

      });

Inputs:

 <th><input class="form-control" name="query" type="text" value=""  aria-label="Search"></th>
                            
 <button type="button" name="search" id="search" class="btn btn-success">Search</button>

Controller:

 public function fullSearch(Request $request) {
        if($request->ajax()) {
            $data = Computer::search($request->get('query'))->get();
            return response()->json($data);
     }
    }

Route:

Route::post('/data/action', '[email protected]')->name('search');

My html document has this in the

 <meta name="csrf-token" content="{{ csrf_token() }}">
Activity icon

Replied to 302 Found On POST Request

Nvm I fixed it.

Activity icon

Replied to 302 Found On POST Request

If you need me to post my regular form and it's functions / jQuery to toggle the form I can.

Activity icon

Started a new Conversation 302 Found On POST Request

On my website I have two separate forms. The first form the user fills it in and uploads a CSV File to the form. The POST Request works for this and stores the data. I have a toggle button on the same form to switch it to a "Manual Entry" Form to fill out all the fields manually that were in csv but it's not POSTing and I keep getting a 302 found in my network tab in chrome dev tools. I tried dumping the request on that controller function but it's not even hitting the route for some reason.

Route:

Route::post('/manualEntry', '[email protected]')->name('store');

Controller Function:

   public function store(Request $request) {
        $attributes = request()->validate([
            'first_name'        =>  'required',
            'last_name'         =>  'required',
            'phone_ext'         =>  'required',
            'email'             =>  'required',
            'location'          =>  'required',
            'campus'            =>  'required',
            'building'          =>  'required',
            'room'              =>  'required',
            'device_type'       =>  'required',
            'asset_tag'         =>  'required',
            'comments'          =>  'required',
            'pc_name'           =>  'required',
            'system_type'       =>  'required',
            'manufacturer'      =>  'required',
            'model'             =>  'required',
            'serial_number'     =>  'required',
            'domain'            =>  'required',
            'user_name'         =>  'required',
            'os_name'           =>  'required',
            'os_version'        =>  'required',
            'os_sp'             =>  'required',
            'os_build_version'  =>  'required',
            'cpu_name'          =>  'required',
            'cpu_cores'         =>  'required',
            'memory_slots'      =>  'required',
            'memory_slots_used' =>  'required',
            'memory_installed'  =>  'required',
            'max_memory'        =>  'required',
            'disk_size'         =>  'required',
            'free_space'        =>  'required',
            'used_space'        =>  'required',
            'ip_address'        =>  'required',
            'mac_address'       =>  'required',
            'motherboard'       =>  'required',
            'mb_manufacturer'   =>  'required',
            'mb_serial_number'  =>  'required',
            'mb_product_number' =>  'required'  
        ]);

        Computer::create($attributes);
    dd($attributes);

        return redirect('/');
    }

Form:

           <form method="POST" action="{{ route('store') }}"  id="manualForm" style="display: none;">
                              @csrf
                              <div class="form-group">
                                  <label for="firstname">First Name:</label>
                                  <input type="text" class="form-control" id="inputFirstname" name="first_name">
                              </div>
                              <div class="form-group">
                                  <label for="lastname">Last Name:</label>
                                  <input type="text" class="form-control" id="inputLastname" name="last_name">
                              </div>
                              <div class="form-group">
                                <label for="phoneExt">Phone Ext:</label>
                                <input type="text" class="form-control" id="phoneExt" name="phone_ext">
                              </div>
                              <div class="form-group">
                                <label for="email">Email:</label>
                                <input type="text" class="form-control" id="email" name="email">
                              </div>
                              <div class="form-group">
                                <label for="location">Location:</label>
                                <input type="text" class="form-control" id="location" name="location">
                              </div>
                              <div class="form-group">
                                <label for="campus">Campus:</label>
                                <input type="text" class="form-control" id="campus" name="campus">
                              </div>
                              <div class="form-group">
                                <label for="building">Building:</label>
                                <input type="text" class="form-control" id="building" name="building">
                              </div>
                              <div class="form-group">
                                <label for="room">Room:</label>
                                <input type="room" class="form-control" id="room" name="room">
                              </div>
                              <div class="form-group">
                                <label for="deviceType">Device Type (e.g. Desktop, Laptop):</label>
                                <input type="deviceType" class="form-control" id="deviceType" name="device_type">
                              </div>
                              <div class="form-group">
                              <label for="assetTag">Asset Tag:</label>
                              <input type="text" class="form-control" id="inputAssetTag" name="asset_tag">
                              </div>
                              <div class="form-group">
                                <label for="comments">Comments:</label>
                                <textarea class="form-control" id="comments" rows="3" name="comments"></textarea>
                              </div>
                              <div class="form-group">
                                <label for="pcName">PC Name:</label>
                                <input type="text" class="form-control" id="pcName" name="pc_name">
                              </div>
                              <div class="form-group">
                                <label for="systemType">System Type:</label>
                                <input type="text" class="form-control" id="systemType" name="system_type">
                              </div>
                              <div class="form-group">
                                <label for="manufacturer">Manufacturer:</label>
                                <input type="text" class="form-control" id="manufacturer" name="manufacturer">
                              </div>
                              <div class="form-group">
                                <label for="model">Model:</label>
                                <input type="text" class="form-control" id="model" name="model">
                              </div>
                              <div class="form-group">
                                <label for="serialNumber">Serial Number:</label>
                                <input type="text" class="form-control" id="serialNumber" name="serial_number">
                              </div>
                              <div class="form-group">
                                <label for="domain">Domain:</label>
                                <input type="text" class="form-control" id="domain" name="domain">
                              </div>
                              <div class="form-group">
                                <label for="username">Username:</label>
                                <input type="text" class="form-control" id="username" name="username">
                              </div>
                              <div class="form-group">
                                <label for="osName">OS Name:</label>
                                <input type="text" class="form-control" id="osName" name="os_name">
                              </div>
                              <div class="form-group">
                                <label for="osVersion">OS Version:</label>
                                <input type="text" class="form-control" id="osVersion" name="os_version">
                              </div>
                              <div class="form-group">
                                <label for="osSP">OS SP:</label>
                                <input type="text" class="form-control" id="osSP" name="os_sp">
                              </div>
                              <div class="form-group">
                                <label for="osBuildVersion">OS Build Version:</label>
                                <input type="text" class="form-control" id="osBuildVersion" name="os_build_version">
                              </div>
                              <div class="form-group">
                                <label for="cpuName">CPU Name:</label>
                                <input type="text" class="form-control" id="cpuName" name="cpu_name">
                              </div>
                              <div class="form-group">
                                <label for="cpuCores">CPU Cores:</label>
                                <input type="text" class="form-control" id="cpuCores" name="cpu_cores">
                              </div>
                              <div class="form-group">
                                <label for="memorySlots">Memory Slots:</label>
                                <input type="text" class="form-control" id="memorySlots" name="memory_slots">
                              </div>
                              <div class="form-group">
                                <label for="memorySlotsUsed">Memory Slots Used:</label>
                                <input type="text" class="form-control" id="memorySlotsUsed" name="memory_slots_used">
                              </div>
                              <div class="form-group">
                                <label for="memorySlotsInstalled">Memory Slots Installed:</label>
                                <input type="text" class="form-control" id="memorySlotsInstalled" name="memory_installed">
                              </div>
                              <div class="form-group">
                                <label for="maxMemory">Max Memory:</label>
                                <input type="text" class="form-control" id="maxMemory" name="max_memory">
                              </div>
                              <div class="form-group">
                                <label for="diskSize">Disk Size:</label>
                                <input type="text" class="form-control" id="diskSize" name="disk_size">
                              </div>
                              <div class="form-group">
                                <label for="freeSpace">Free Space:</label>
                                <input type="text" class="form-control" id="freeSpace" name="free_space">
                              </div>
                              <div class="form-group">
                                <label for="usedSpace">Used Space:</label>
                                <input type="text" class="form-control" id="usedSpace" name="used_space">
                              </div>
                              <div class="form-group">
                                <label for="ipAddress">IP Address:</label>
                                <input type="text" class="form-control" id="ipAddress" name="ip_address">
                              </div>
                              <div class="form-group">
                                <label for="macAddress">MAC Address:</label>
                                <input type="text" class="form-control" id="macAddress" name="mac_address">
                              </div>
                              <div class="form-group">
                                <label for="motherboard">Motherboard:</label>
                                <input type="text" class="form-control" id="motherboard" name="motherboard">
                              </div>
                              <div class="form-group">
                                <label for="mbManufacturer">Mobo Manufacturer:</label>
                                <input type="text" class="form-control" id="mbManufacturer" name="mb_manufacturer">
                              </div>
                              <div class="form-group">
                                <label for="mbSerialNumber">Mobo Serial Number:</label>
                                <input type="text" class="form-control" id="mbSerialNumber" name="mb_serial_number">
                              </div>
                              <div class="form-group">
                                <label for="mbProductNumber">Mobo Product Number:</label>
                                <input type="text" class="form-control" id="mbProductNumber" name="mb_product_number">
                              </div>
                                <br>
                              <button type="submit" class="btn btn-primary">Submit</button>
                              <button type="button" class="btn btn-secondary" id="manualEntry">Manual Entry</button>
                          </form>

Migration:

public function up()
    {
        Schema::create('computers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('first_name');
            $table->string('last_name');
            $table->string('full_name');
            $table->string('phone_ext');
            $table->string('email');
            $table->string('location');
            $table->string('campus');
            $table->string('building');
            $table->string('room');
            $table->string('device_type');
            $table->string('asset_tag');
            $table->string('comments');
            $table->string('pc_name');
            $table->string('system_type');
            $table->string('manufacturer');
            $table->string('model');
            $table->string('serial_number');
            $table->string('domain');
            $table->string('user_name');
            $table->string('os_name');
            $table->string('os_version');
            $table->string('os_sp');
            $table->string('os_build_version');
            $table->string('cpu_name');
            $table->string('cpu_cores');
            $table->string('memory_slots');
            $table->string('memory_slots_used');
            $table->string('memory_installed');
            $table->string('max_memory');
            $table->string('disk_size');
            $table->string('free_space');
            $table->string('used_space');
            $table->string('ip_address');
            $table->string('mac_address');
            $table->string('motherboard');
            $table->string('mb_manufacturer');
            $table->string('mb_serial_number');
            $table->string('mb_product_number');
            $table->timestamps();
        });
    }
Feb
07
3 months ago
Activity icon

Started a new Conversation Multiple Search Boxes Filter

How would you go about implementing a multiple filtered search for data. So you have the ability to filter on multiple criteria's using multiple search boxes? Right now I have a single search box but I want to have mutiple search boxes:

Here's an image to show what I mean: https://gyazo.com/1215580cd1a34ccdce8ccd0d689b3a08

Here's my current live search functionality.

Form:

<form method="GET" action="{{route('search')}}" class="search-form">
                              <th><input class="form-control" name="query" type="text" value="{{ request()->input('query') }}"  aria-label="Search"></th>
                            </form>

Controller:

  function search(Request $request) {
        $query = $request->input('query');

        $computers = Computer::where('full_name', 'like', "%$query%")
                            ->orWhere('email', 'like', "%$query%")
                            ->orWhere('campus', 'like', "%$query%")
                            ->orWhere('location', 'like', "%$query%")
                            ->orWhere('device_type', 'like', "%$query%")
                            ->orWhere('asset_tag', 'like', "%$query%")
                            ->orWhere('building', 'like', "%$query%")
                            ->orWhere('room', 'like', "%$query%")->get();


        return view('search-results', compact('computers'));
    }

Route:

Route::get('/data/search', '[email protected]')->name('search');
Jan
31
3 months ago
Activity icon

Replied to Import CSV + Form Inputs To Same Mysql Table.

Awesome, thank you! This worked.

'pc_name' => request('pc_name') 
Activity icon

Started a new Conversation Import CSV + Form Inputs To Same Mysql Table.

I'm using the laravel excel-package - https://docs.laravel-excel.com/3.1/imports/model.html

tl;dr: How can I push an imported csv file + form data to the same mysql table using the laravel-excel package?

Right now I have a form with a file upload input. I'm able to successfully upload a CSV file and push it to my database with the following code:

ComputerController:

    public function csv_import(Request $request) {
        Excel::import(new CsvImport, $request->file('file'));
        return back();
    }

CSV Import:

class CsvImport implements ToModel
{
    
    public function model(array $row)
    {
        return new Computer([
            'first_name' => $row[0],
            'last_name' => $row[1],
            'asset_tag' => $row[2],
        ]);

    }
}

What I want to do is the following: Have a form with one input and one file upload: e.g

 <input type="file" class="custom-file-input" id="inputFile" name="file">
<input type="text" class="form-control" id="pcname" name="pc_name">

Then upload your file in the form and fill out the pc_name input and have all the data pushed to the same table. I'm not sure how to do that. I tried passing $pc_name as a parameter into csv_import function like the following.

   public function csv_import(Request $request) {
        $pc_name = $request->pc_name;
        Excel::import(new CsvImport, $request->file('file'), $pc_name);
        return back();
    }

    public function model(array $row, $pc_name)
    {
        return new Computer([
            'first_name' => $row[0],
            'last_name' => $row[1],
            'asset_tag' => $row[2],
        'pc_name' => $pc_name
        ]);

        
    }

When I try to pass the function $pc_name, i get the following error:

Declaration of App\Imports\CsvImport::model(array $row, $pc_name) must be compatible with Maatwebsite\Excel\Concerns\ToModel::model(array $row)
Dec
19
5 months ago
Activity icon

Replied to Query By Month And Year

I got it working, the issue was my whereMonth. I had to parse the month and return the number for the year.

Activity icon

Started a new Conversation Query By Month And Year

I'm trying to query by the month and year but it's returning an empty array for each month. Here's my function

    public function month($id, Request $request){
        $user = auth()->user();
        $month = $request->month;
        $year = $request->year;

        dd($times = Time::where('user_id', $id)
        ->whereYear('start_day', $request->year)
        ->whereMonth('start_day', $request->month)
        ->get());
       

        return view ('admin.report.month', compact('month', 'year', 'user'));
    }

All my requests are working properly.

Dec
14
5 months ago
Activity icon

Replied to Function Parameters Help

Yea exactly, i want to show the data for prior year to the selected one

Activity icon

Replied to Function Parameters Help

I'm extracting the values like this, so i'm not sure how I could do this with a collection

 $reportValues = self::getReportValues($id, $request);
        extract($reportValues);
Activity icon

Replied to Function Parameters Help

Since I was re-using a ton of code in multiple controllers, I made a helper file and wrapped all the data inside an array.

I can post the full func if you want but it's like 150lines of code.

At the end of the function i'm doing this:

$data = [
            'all_ot' => $all_ot,
            'all_comp' => $all_comp,
            'all_vacation' => $all_vacation,
            'all_personal' => $all_personal,
            'all_sick' => $all_sick,
            'calculator' => $calculator,
            'total_ot' => $total_ot,
            'total_comp' => $total_comp,
            'total_vacation' => $total_vacation,
            'total_personal' => $total_personal,
            'total_sick' => $total_sick,
            'vacation_allotment' => $vacation_allotment,
            'vacation_carry_over' => $vacation_carry_over,
            'work_day' => $work_day,
            'personal_time_allotment' => $personal_time_allotment,
            'overtime' => $overtime,
            'year' => $request->year,
            'balance_in_hours_ot' => $balance_in_hours_ot,
            'balance_in_hours_vacation' => $balance_in_hours_vacation
        ];

        return $data;
Activity icon

Started a new Conversation Function Parameters Help

Right now i'm calling a function that outputs a bunch of data. I'm storing a year variable in the data. Is there a way to call the function and extract data belonging to a certain year? I can post more code if you guys need it:

Function: $update_carry_over = ReportHelper::getReportValues($id, $request));

dd of $update_carry_over:

array:19 [▼
  "all_ot" => array:1 [▶]
  "all_comp" => []
  "all_vacation" => []
  "all_personal" => []
  "all_sick" => []
  "calculator" => Time {#334 ▶}
  "total_ot" => 97200
  "total_comp" => 0
  "total_vacation" => 0
  "total_personal" => 0
  "total_sick" => 0
  "vacation_allotment" => 0
  "vacation_carry_over" => 0
  "work_day" => 0
  "personal_time_allotment" => 0
  "overtime" => 0
  "year" => "2019"
  "balance_in_hours_ot" => "40:30"
  "balance_in_hours_vacation" => "0:00"
]

Right now that's the data when I click on a user's 2019 view. I want to use the previous use data inside of the 2019 view

Dec
13
5 months ago
Activity icon

Started a new Conversation Help With Logic

I need some help with logic. I currently building a time tracking software. I have an edit view where it shows all the years the user has time entries in a table. I added to the table the lowest year - 1 and the highest year + 1, and each redirect to my create view. Here's my table in my edit view:

 <table class="table table-striped table-sm">
                <thead>
                    <tr>
                        <th scope="col">Years</th>
                    </tr>
                </thead>
                <tbody>
                  
                        <tr>
                            <td>
                                <a href="/admin/staff/{{ $user->id }}/create"><p style="color:maroon; font-weight:bold;">{{ $min_year - 1}} - Add New</p></a>
                            </td>
                        </tr>
                    @foreach($years as $year)
                        <tr>
                            <td>
                                <a href="/admin/staff/{{ $user->id }}/{{ $year }}/edit"><p style="color:maroon; font-weight:bold;">{{ $year }}</p></a>
                            </td>
                        </tr>
                    @endforeach
                    <tr>
                        <td>
                            <a href="/admin/staff/{{ $user->id }}/create" ><p style="color:maroon; font-weight:bold;">{{ $max_year + 1}} - Add New</p></a>
                        </td>
                    </tr>
                </tbody>
                </table>   

Right now my create route is is just:

Route::get('admin/staff/{staff}/create/{year}', 'Admin\[email protected]')->name('admin.staff.create');

My form POST:

<form method="POST" action="/admin/staff/{{ $offtime->id }}">

I'm wondering how I can grab the year on the edit view, and pass it into my form post so it grabs the correct year.

So example lets say the user only logged time for 2019.

The table would look like this:

2018 - Add New
2019
2020 - Add New

The 2018 - Add new would redirect to ('admin/staff/{staff}/create/2018

Dec
07
5 months ago
Activity icon

Replied to Year Default Value In Migration

That works, thank you :)

Activity icon

Started a new Conversation Year Default Value In Migration

I have a years column in my migrations, is there a way to make the default year the current year?

I tried doing this:

$table->year('year')->default('2019');  but the year logged to my database is '2000'

Also tried this and it doesn't work

$table->year('year')->default(date("Y"));
Activity icon

Replied to Update Data Failed

@piljac1 Using first() fixed the problem. Thank you :)

Activity icon

Started a new Conversation Update Data Failed

I'm trying to update data and it's failing with this error: Method Illuminate\Database\Eloquent\Collection::update does not exist.

Here's my code:

Update method:

    public function update($id, Request $request, $year)
    {
        $offtime = Offtime::where('user_id', $id)->whereYear('year', $year )->get();
        $offtime->update(request(['work_day','vacation_allotment','personal_time_allotment','overtime','vacation_carry_over','use_carry_over']));
        
        $offtime->save();

        return back();
    }

route:

Route::patch('admin/staff/{staff}/{year}', 'Admin\[email protected]')->name('admin.staff.update')->middleware('admin');

Form URL:

 <form method="POST" action="/admin/staff/{{ $id }}/{{ $year}}">
                    @csrf
                    {{ method_field('PATCH') }}
Dec
04
5 months ago
Activity icon

Started a new Conversation Parse Url

I have a url that looks like this: http://localhost:8000/admin/staff/1/2000/edit

It changes based on the year I select. Is there a way to extract the year from the url? So in this case I'de want to extract "2000"

Dec
02
5 months ago
Activity icon

Replied to Request Null

Ok I changed the Form from a POST to a GET Request and now it's grabbing the year in show. Except now i'm getting this error:

The Response content must be a string or object implementing __toString(), "boolean" given.

Any ideas?

Activity icon

Replied to Request Null

Argument 2 passed to Symfony\Component\HttpFoundation\RedirectResponse::__construct() must be of the type int, array given, called in

Thats the error i'm getting.

Like I said before the query works properly in getReport, is there a way I can use something like find to return the correct data like i'm doing for $user. I know find won't work because it only grabs one value

Activity icon

Replied to Request Null

Is there another way I could fix this?

Activity icon

Replied to Request Null

Method App\Http\Controllers\Admin\ReportController::index does not exist. Now i'm getting this and the url in my brower is:

http://localhost:8000/admin/reports?id=1&year=2019

Activity icon

Replied to Request Null

The HTTP status code "2019" is not valid.

Now i'm getting this error when I pass the year in my request

if ($user) {
            return redirect()->route('admin.reports.show', $user->id, $year);
        }

I can get the correct times inside of my getReport function like this:

times = Time::where('user_id', $form_user)->whereYear('start_day', $year)->get();

Full method:

    }

    public function getReport(Request $request) {


        $form_user = $request->form_user;
        $reportTypeForm = $request->reportTypeForm;
        $year = $request->year;
        
        $times = Time::where('user_id', $form_user)->whereYear('start_day', $year)->get();
    

        if (!$form_user) {
            return abort(404);
        }
        $user = User::find($form_user);
        if ($user) {
            return redirect()->route('admin.reports.show', $user->id, $year);
        }
        return abort(404);
    }

Is there a way to get this to work through this function?

Activity icon

Replied to Request Null

<form method="POST" action="{{ route('admin.getReport') }}"> Thats the POST on my form

The url for my show would be: http://localhost:8000/admin/reports/{id}

Activity icon

Replied to Request Null

Not sure what you mean. Change the my routes in my web.php?

Activity icon

Replied to Request Null

If I dd($request->all()) inside of public function show() it just returns an empty array: [ ]

If i dd($request->all()) inside of public function getReports() it returns:

array:4 [▼
  "_token" => "zb8d8Wrvofa5Rk2L18d1HM9R4G7svOFi0Lrg2QHK"
  "form_user" => "1"
  "reportTypeForm" => "Yearly"
  "year" => "2019"
]
Activity icon

Replied to Request Null

@sinnbeck Updated it in my op

Activity icon

Started a new Conversation Request Null

I'm getting a return of null when i dump $request inside of my public function show() method. I'm trying to get this line to work: $times = Time::where('user_id', $id)->whereYear('start_day', $request->year)->get();, but since the request is null it obviously won't query. If I dump $year inside of my public function getReports(), i'll get the correct year I selected from my form. I believe the issue is how i'm calling getReports, but i'm not sure how to fix it. Is there a way to pass that $year value into my show function?

Here's my entire controllers + Routes:

Report Controller:


<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Time;
use App\User;
use App\Category;
use App\Offtime;

use Carbon\Carbon;

use Auth;
use Date;
use PDF;


class ReportController extends Controller
{

    public function create() {

        $users = User::all();
        $times = Time::all();
        $years = array();

        $length_times = count($times);
        for($i=0;$i<$length_times;$i++){
            $year = Carbon::parse($times[$i]->start_day)->format('Y');
            array_push($years, $year);
        }

        $years = array_unique($years);

        return view('admin.report.create', compact('users', 'years'));
    }

    public function show($id, Request $request) {

        $user = User::find($id);
        if (!$user) {
            return false;
        }
        
        dd($request);


        $all_ot = array();
        $all_comp = array();
        $all_vacation = array();
        $all_personal = array();
        $all_sick = array();
   
        $total_ot = 0;
        $total_comp = 0;
        $total_vacation = 0;
        $total_personal = 0;
        $total_sick = 0;

        $times = Time::where('user_id', $id)->whereYear('start_day', $request->year)->get();
        $offtime = Offtime::where('user_id', $id)->get();
        
        $work_day = $this->timeToSeconds($offtime[0]->work_day);
        $vacation_allotment = $this->timeToSeconds($offtime[0]->vacation_allotment);
        $vacation_carry_over = $this->timeToSeconds($offtime[0]->vacation_carry_over);
        $personal_time_allotment = $this->timeToSeconds($offtime[0]->personal_time_allotment);
        $overtime = $this->timeToSeconds($offtime[0]->overtime);
        
        foreach ($times as $time) {
            for ($i = 1; $i <= 12; $i++) {
                $month = Carbon::parse($time->start_day)->format('m');
                if ($month == $i) {
                    switch ($time->category_id) {
                        case 1:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_ot)) {
                                $all_ot[$i] = $totalDuration;
                            } else {
                                $all_ot[$i] += $totalDuration;
                            }
                            break;
                        case 2:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_comp)) {
                                $all_comp[$i] = $totalDuration;
                            } else {
                                $all_comp[$i] += $totalDuration;
                            }
                            break;
                        case 3:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_vacation)) {
                                $all_vacation[$i] = $totalDuration;
                            } else {
                                $all_vacation[$i] += $totalDuration;
                            }
                            break;
                        case 4:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_personal)) {
                                $all_personal[$i] = $totalDuration;
                            } else {
                                $all_personal[$i] += $totalDuration;
                            }
                            break;
                        case 5:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_sick)) {
                                $all_sick[$i] = $totalDuration;
                            } else {
                                $all_sick[$i] += $totalDuration;
                            }
                            break;
                    }
                }
            }
        }
        $calculator = new Time();

        // Total Counts
        $ot = array_values($all_ot);
        $length_ot = count($ot);
        for ($i = 0; $i < $length_ot; $i++) {
            $total_ot += $ot[$i];
        }
        $comp = array_values($all_comp);
        $length_comp = count($comp);
        for ($i = 0; $i < $length_comp; $i++) {
            $total_comp += $comp[$i];
        }
        $vacation = array_values($all_vacation);
        $length_vacation = count($vacation);
        for ($i = 0; $i < $length_vacation; $i++) {
            $total_vacation += $vacation[$i];
        }
        $personal = array_values($all_personal);
        $length_personal = count($personal);
        for ($i = 0; $i < $length_personal; $i++) {
            $total_personal += $personal[$i];
        }
        $sick = array_values($all_sick);
        $length_sick = count($sick);
        for ($i = 0; $i < $length_sick; $i++) {
            $total_sick += $sick[$i];
        }

        return view ('admin.report.show', compact('all_ot', 'all_comp', 'all_vacation', 'all_personal', 'all_sick', 'user', 'calculator', 'total_ot', 'total_comp', 'total_vacation', 'total_personal', 'total_sick','vacation_allotment', 'vacation_carry_over', 'work_day', 'personal_time_allotment', 'overtime'));
    }

    public function getReport(Request $request) {
        $form_user = $request->form_user;
        $reportTypeForm = $request->reportTypeForm;
        $year = $request->year;


        if (!$form_user) {
            return abort(404);
        }
        $user = User::find($form_user);
        if ($user) {
            return redirect()->route('admin.reports.show', $user->id);
        }
        return abort(404);
    }


    private static function timeToSeconds($time)
    {
        sscanf($time, "%d:%d:%d", $hours, $minutes, $seconds);
        return $time = isset($hours) ? $hours * 3600 + $minutes * 60 + $seconds : $minutes * 60 + $seconds;
    }
}

Routes:

Route::resource('admin/reports', 'Admin\ReportController', [ 'as' => 'admin'])->middleware('admin');
Route::post('admin/reports/getReport', 'Admin\[email protected]')->name('admin.getReport')->middleware('admin');
Dec
01
5 months ago
Activity icon

Replied to Retrieving Data By The Year

@Sinnbeck that isn't working. Could it be because it's an array of arrays?

Here's a dump of the data:

Collection {#346 ▼
  #items: array:4 [▼
    0 => Time {#347 ▶}
    1 => Time {#348 ▶}
    2 => Time {#349 ▶}
    3 => Time {#350 ▼
      #guarded: []
      #connection: "mysql"
      #table: "times"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:10 [▼
        "id" => 6
        "user_id" => 1
        "category_id" => 1
        "start_day" => "2021-04-18"
        "start_time" => "11:10:00"
        "finish_time" => "23:10:00"
        "duration" => "12:00:00"
        "notes" => "Test"
        "created_at" => "2019-12-01 16:10:42"
        "updated_at" => "2019-12-01 16:10:42"
      ]
      #original: array:10 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
    }
  ]
}
Activity icon

Started a new Conversation Retrieving Data By The Year

Currently I have a report that collects time entries from any year. What I want to do is only select the time time entries that are associated with the year I select on the form.

Here's my form-group for years on my report.create view

<div class="form-group">
    <label for="year"><b>Year</b></label>
    <select name="year" class="form-control" id="timeYearForm" placeholder="Select Year">
             @foreach ($years as $year)
                       <option>
                            {{ $year }}
                        </option>
               @endforeach
    </select>
 </div>

Report Create view:

 public function create()
    {

        $users = User::all();
        $times = Time::all();

        $years = array();

        $length_times = count($times);
        for($i=0;$i<$length_times;$i++){
            $year = Carbon::parse($times[$i]->start_day)->format('Y');
            array_push($years, $year);
        }

        $years = array_unique($years);

    
        
      
        return view('admin.report.create', compact('users', 'years'));
    }

Here's how i'm grabbing the current data:

      $times = Time::where('user_id', $id)->get();

In my times migration I have a column called "start_day" that's tracking the date for the time entry.

I tried using carbon parse like this to select the date, but I was getting a weird date-time error:

$times = Time::where('user_id', $id)->where(Carbon::parse('start_day')->format('Y'), $request->year)->get();

Error: DateTime::__construct(): Failed to parse time string (start_day) at position 0 (s): The timezone could not be found in the database

Any ideas on how to resolve this? Or use a different approach to get the year?. I'll post more code if you need me too

Nov
27
6 months ago
Activity icon

Replied to Loop Not Working

@Dalma What would be the solution to this?

Activity icon

Replied to Loop Not Working

It's not pushing to the array. I'm getting this error: "Illegal offset type"

Activity icon

Started a new Conversation Loop Not Working

Not sure why this loop isn't working. I'm trying to loop through all my time entries and push the year into an array. I made $year an array value because when I was pushing it into the array originally, i was getting an error "Tried to pass string value instead of array value". Not sure what's wrong

$times = Time::where('user_id', $id)->get();
$years = array();
   foreach($times as $time) {
            $year = array(Carbon::parse($time->start_day)->format('Y'));
            $years = array_push($year[$time]);
        }
Activity icon

Started a new Conversation Group By Month And Year

Currently i'm grouping a bunch of data by months. How can I group it by the year and months? Here's my function

  foreach ($times as $time) {
            for ($i = 1; $i <= 12; $i++) {
                $month = Carbon::parse($time->start_day)->format('m');
                if ($month == $i) {
                    switch ($time->category_id) {
                        case 1:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_ot)) {
                                $all_ot[$i] = $totalDuration;
                            } else {
                                $all_ot[$i] += $totalDuration;
                            }
                            break;
                        case 2:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_comp)) {
                                $all_comp[$i] = $totalDuration;
                            } else {
                                $all_comp[$i] += $totalDuration;
                            }
                            break;
                        case 3:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_vacation)) {
                                $all_vacation[$i] = $totalDuration;
                            } else {
                                $all_vacation[$i] += $totalDuration;
                            }
                            break;
                        case 4:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_personal)) {
                                $all_personal[$i] = $totalDuration;
                            } else {
                                $all_personal[$i] += $totalDuration;
                            }
                            break;
                        case 5:
                            $totalDuration = Carbon::parse($time->start_time)->diffInSeconds(Carbon::parse($time->finish_time));
                            if (!array_key_exists($i, $all_sick)) {
                                $all_sick[$i] = $totalDuration;
                            } else {
                                $all_sick[$i] += $totalDuration;
                            }
                            break;
                    }
                }
            }
        }