Danieloplata

Danieloplata

Member Since 1 Year Ago

Experience Points
28,560
Total
Experience

1,440 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
259
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 6
28,560 XP
Feb
18
1 month ago
Activity icon

Replied to Tips On Streamlining CSS

Absolutely recommend tailwindcss, and when it comes to streamlining - purgecss will dramatically reduce the size of your css/js files

Jan
13
2 months ago
Activity icon

Replied to 404 On Auth Routes

Thanks Tykus, this makes sense! The change I made to the URI's previously was to drop part of the URI.

Originally it looked like "portal.example.org/portal/{respondent}", was asked to remove the second portal from the URI.. So it became "portal.example.org/{respondent}" and now due to my route order, it's incorrectly trying to match the word "login" with a respondent!

I've moved the Auth::routes(); to the top of my file and can confirm it's now working again :)

Activity icon

Replied to 404 On Auth Routes

// Portal routes
Route::get('/{respondent}', '[email protected]')->name('portal');

// Survey Routes
Route::get('/{respondent}/survey/{survey}', '[email protected]')->name('survey');
Route::post('/survey/{survey}', '[email protected]')->name('storeSurvey');

// Respondent routes
Route::get('/', '[email protected]')
Route::get('/respondents', '[email protected]')->name('respondents');
Route::get('/respondent/{respondent}/surveys', '[email protected]')->name('respondentSurveys');
Route::get('/respondents/export', '[email protected]')->name('exportRespondents');

Auth::routes();

All routes are working, but trying to use /login or /register do not

Activity icon

Replied to 404 On Auth Routes

@bobbybouwmann Yes I still have that in the routes/web

The error is occuring both on my local environment and on live

Activity icon

Started a new Conversation 404 On Auth Routes

I've managed to somehow break the scaffolded auth for my project - my routes generated by Auth all return a 404. The rest of my project can be accessed.

The problem occured after I had to reset my route cache after changing some route URI's

Can anyone help with this?

Here is my route:list

Routes

In Illuminate\Routing\Router:

$this->get('login', 'Auth\[email protected]')->name('login');

The trait in the login controller points to this in Auth\AuthenticatesUsers

public function showLoginForm()
{
    return view('auth.login');
}

The view exists (was previously working and PHPStorm can still resolve it) and adding dd('test') above it doesn't affect the 404, I don't think the code even reaches past the route.

Activity icon

Replied to 404 On Auth Routes

Since the default laravel auth scaffolding includes a closure in the routes/api file, I have moved it to a controller to allow me to run php artisan route:cache again.

php artisan make:controller Api/Auth

Api/Auth:

class Auth extends Controller
{
    public function __invoke (Request $request) {
        return $request->user();
    }
}

Unfortunately, auth routes are still returning 404 :(

Activity icon

Replied to 404 On Auth Routes

The routes that I changed are working - I am currently looking into whether the new laravelui/auth scaffolding relies on api routes (The project only has the default auth routes at the moment, they remain unchanged)

Activity icon

Replied to 404 On Auth Routes

I've done some digging and it seems that some routes are actually working, I assume that the route caching/clearing worked but something else broke in the meantime.

It appears that just my Auth routes are not working now

Routes

Activity icon

Replied to 404 On Auth Routes

@nakov Hi Nakov, the only error in there is

[2020-01-13 10:41:26] production.ERROR: Unable to prepare route [api/user] for serialization. Uses Closure. {"exception":"[object] (LogicException(code: 0): Unable to prepare route [api/user] for serialization. Uses Closure. 

Which I got earlier when trying to run php artisan route:cache for the first time. I resolved this by removing the default laravel api route (my project doesn't use api routes)

Activity icon

Started a new Conversation 404 On Auth Routes

Hi guys, I've pushed a small update to a project that changed the URI's for a couple routes and now I'm returning 404 on all routes except /

UPDATE: this is now just for Auth routes

Google is full of these issues being an initial setup issue, and on apache - my issue is mid-project and nginx which I created using forge. This has been working fine until now.

My route:list shows all the correct routes.

I've ran the following commands:

  • composer dump-autoload
  • php artisan cache:clear
  • php artisan route:cache
Oct
29
5 months ago
Activity icon

Replied to Looking To Improve A Piece Of Code

@martinbean Thanks for your solution, I initially did not understand how this should be implemented, so big thanks to @sinnbeck and @yoeriboven for your help too :)

Oct
23
5 months ago
Activity icon

Replied to Looking To Improve A Piece Of Code

Thanks for your reply @martinbean, this is exactly what I had in mind. Can I ask you to elaborate on how exactly this should be set up?

This isn't something I've tried before and had a bit of trouble finding anything on google relevant to this.

I tried the below as SurveyCollection.php under the app folder (not sure if I need to register this anywhere)

use App\Survey;
use Illuminate\Database\Eloquent\Collection;

class SurveyCollection extends Collection
{
    public function areComplete(): bool
    {
        // Determine if all surveys are complete by rejecting
        // completed surveys and checking that collection is then empty
        return $this->reject(function (Survey $survey) {
            return $survey->pivot->completed;
        })->isEmpty();
    }
}

Result: Method Illuminate\Database\Eloquent\Collection::areComplete does not exist

Activity icon

Started a new Conversation Looking To Improve A Piece Of Code

I'm trying to improve my code, especially the check for completed surveys in card.blade.php - but I don't know how I can do this in a cleaner way. I tried playing around using the every() function but couldn't get anything working. Because of how this data is being requested, I don't know how I can extract it to it's own class/function.

PortalController

public function index()
{
    $days = Session::get('respondent')
        ->surveys()
        ->withPivot('completed')
        ->get()
        ->groupBy(function ($val) {
            return Carbon::parse($val->date)->format('d');
        });

    return view('portal.index', compact('days'));
}

Index.blade.php

<main class="lg:flex lg:flex-wrap -mx-3">
    @forelse ($days as $day => $surveys)
        <div class="lg:w-1/3 px-3 pb-6">
            @include ('portal.card')
        </div>
    @empty
        <div>No surveys have been added to your account yet.</div>
    @endforelse
</main>

$surveys is a collection, containing an array of objects. There are 3 surveys per day, for 7 days. Each survey has a pivot attached, containing a boolean for whether or not it is completed.

Card.blade.php

<footer>
    // I would really like to change the below line, so ugly!
    @if ($surveys['0']->pivot->completed && $surveys['1']->pivot->completed && $surveys['2']->pivot->completed)
        <div class="text-green-600">All surveys complete</div>
    @else
        <div class="text-red-600">You still have surveys to complete</div>
    @endif
</footer>
Activity icon

Awarded Best Reply on Group Collection Results By Date

I managed to get it working by using the link given by @jlrdw

// AppointmentController.index
$days = Session::get('uniqueid')
    ->appointments()
    ->withPivot('completed')
    ->get()
    ->groupBy(function ($val) {
        return Carbon::parse($val->date)->format('d');
    });

// Appointments.blade.php
@forelse ($days as $day => $appointments)
    <div class="lg:w-1/3 px-3 pb-6">
        @include ('appointment_times.card')
    </div>
@empty
    <div>No appointments are available at the moment. Please check back later.</div>
@endforelse

// appointment_times.card
@foreach ($appointments as $appointment)
...
@endforeach
Activity icon

Replied to Group Collection Results By Date

I managed to get it working by using the link given by @jlrdw

// AppointmentController.index
$days = Session::get('uniqueid')
    ->appointments()
    ->withPivot('completed')
    ->get()
    ->groupBy(function ($val) {
        return Carbon::parse($val->date)->format('d');
    });

// Appointments.blade.php
@forelse ($days as $day => $appointments)
    <div class="lg:w-1/3 px-3 pb-6">
        @include ('appointment_times.card')
    </div>
@empty
    <div>No appointments are available at the moment. Please check back later.</div>
@endforelse

// appointment_times.card
@foreach ($appointments as $appointment)
...
@endforeach
Oct
22
5 months ago
Activity icon

Started a new Conversation Group Collection Results By Date

Hi guys,

I'm trying to group a collection by date, so that I can print them to a page by creating a foreach loop per date, rather than per appointment (shown below). I'm not very familiar with the syntax used here, so I worry I might be way off.

This is what I've got so far:

// AppointmentController.index
...
$appointments = Session::get('uniqueid')->appointments()->groupBy('date')->get();

// appointments.blade.php
...
@forelse ($appointments as $appointments->date => $appointment)
    <div class="lg:w-1/3 px-3 pb-6">
        @include ('appointment_times.card')
    </div>
@empty
    <div>No appointments available at the moment. Please check back later.</div>
@endforelse

There are 3 possible appointments per day, over a 7 day period. I want to show 7 of my appointment cards on the page, with the 3 appointments for that day on each.

$appointments = Session::get('uniqueid')->appointments // returns all 21 appointments
$appointments = Session::get('uniqueid')->appointments()->groupBy('date')->get(); // returns all 21 appointments with no grouping

Dates are stored in the database as type date with format YYYY-MM-DD