fredmarks

fredmarks

Member Since 1 Year Ago

Experience Points
410
Total
Experience

4,590 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
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
410 XP
Feb
11
8 months ago
Activity icon

Replied to Exception Handler 500 Error

I managed to solve this, thanks to this thread

https://laravel.io/forum/02-19-2015-laravel-5-custom-error-view-for-500

I add this code right at the start of my render method

        if($exception instanceof \Symfony\Component\Debug\Exception\FatalErrorException) {
            return parent::render($request, $exception);
        }

In the words of the user browner12

...when your server throws an error (method does not exist, variable undefined, etc) it actually throws a FatalErrorException. as such, it is uncaught, and trickles down to the SymfonyDisplayer()

Feb
09
8 months ago
Activity icon

Replied to Exception Handler 500 Error

@SNAPEY - I am getting the white screen (i.e. no debug output) in chrome dev tools. Also debugbar shows nothing (no exceptions).

However, If i remove that if(ajax) statement completely, then everything works. i.e. I get all the exceptions showing in dev tools and bugbar.

The only time this is breaking is with 500 exceptions. All others (like the ones in my switch statement) are working and return ajax json as expected

Activity icon

Replied to Exception Handler 500 Error

@BOBBYBOUWMANN -

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler {
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report(Exception $exception) {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception) {

        if ($request->ajax()) {

            //custom ajax errors
            switch ($exception->getStatusCode()) {

            //permission denied
            case 403:
                $response = __('lang.error_no_permission_for_resource');
                break;

            //larevel session timeout
            case 419:
                $response = __('lang.error_session_timeout');
                break;

            //not found
            case 404:
                $response = __('lang.error_not_found');
                break;

            //business logic/generic errors
            case 409:
                $response = __('lang.error_request_could_not_be_completed');
                break;

            default:
                $response = __('lang.error_request_could_not_be_completed');
                break;
            }

            //return response - with error code
            return response()->json(array('message' => $response), $exception->getStatusCode());
        }

        //default laravel response
        return parent::render($request, $exception);
    }
}

Above is my full code

Activity icon

Replied to Exception Handler 500 Error

@BOBBYBOUWMANN - I do have code in the switch, I just did not put it here as it was not relevant.

if ($request->ajax()) {
      $code = $exception->getStatusCode();
}

The error is with $exception->getStatusCode(), even if all I have is the code above, when a 500 exception happens, there is nothing displayed in chrome devtool

Somehow, $exception->getStatusCode(); breaks things

Feb
08
8 months ago
Activity icon

Replied to Exception Handler 500 Error

@BOBBYBOUWMANN - As you have described, the exceptions are showing in my dev tools request tab as expected.

However, the problem I am having is that when I add my ajax if statement in the handler's render method as shown above, I no-longer get the exceptions being displayed in my Chome Dev tool. All I get is a white screen with no response payload

I seem to have narrowed the problem down to this

        //THIS IS CAUSING IT TO BREAK.
        if ($request->ajax()) {
            switch ($exception->getStatusCode()) {
                //it seems that this bit of code is causing the issue. No exceptions showing in dev tools
                //$exception->getStatusCode()

               //even if I suppress it with @$exception->getStatusCode(), the problem remains
            }
        }

        //THIS IS HARMLESS AND IT CONTINUES TO WORK
        if ($request->ajax()) {
            $foo = 'bar';
            switch ($foo) {
                //continues to work as expected & I still get exceptions in chrome devtool
            }
        }

Activity icon

Started a new conversation Exception Handler 500 Error

I have added an some custom exception handling for ajax request

\App\Exeptions\Handler.php


public function render($request, Exception $exception)
{

  //do something different when its an ajax call
  if ($request->ajax() && in_array($exception->getStatusCode(), array(403, 419, 404, 409))) {

      //retun ajax respone

   }

    return parent::render($request, $exception);
}

This is all working fine, however when my code generates a 500 error (e.g. Method does not exist) no output is generated in either debugbar or chrome developer tools.

The only place I now see the exception message is in the log file.

Any ideas how to get around this, so that I can still get my debugging exceptions for 500 errors?

Oct
23
11 months ago
Activity icon

Replied to Validation Ordering

@Cronix @borisu

It may be easier to explain with a screenshot of my form (please see below)

https://unsee.cc/d9f9c8dc/

Activity icon

Replied to Validation Ordering

@Cronix

I have tried your suggesting, but same problem

if existing_client != yes the exists rule should not be getting checked at all, but it is

Activity icon

Replied to Validation Ordering

            'clientid' => [
                'bail',
                'required_if:existing_client,yes',
                Rule::exists('clients', 'id'),
            ],

Still giving the same result.

Bail works once a validation rule has failed.

In this case, the required_if rule is not really failing, given that existing_client != yes

Activity icon

Started a new conversation Validation Ordering

            'clientid' => [
                'required_if:existing_client,yes',
                Rule::exists('clients', 'id'),
            ],

The problem

The exists rule is being checked, even when the required_if returns false (i.e. existing_client != yes)

How can I write this, so that the exists rule is only checked when the required_if rule has passed

Sep
12
1 year ago
Activity icon

Replied to Eloquent Relationships

@Tray2 I have decided to go with your many to many suggestion.... its working great

Sometimes we gotta just keep things simple

Activity icon

Replied to Eloquent Relationships

I could do that but I will end up repeating myself as the application grows

  • task_users
  • project_users
  • ticket_users
  • foo_users

hence, a single assigned model with polymorphic relationships with tasks, tickets, projects

Or maybe I am complicating it :)

Activity icon

Replied to Eloquent Relationships

@Tray2 Thanks for the comment. I do not want the users to have the direct relationship with the projects or task table, I want the relationship to go through the "assigned" table. The reason is that

  • A user can be assigned to many tasks
  • A task can have many users assigned to it
  • I want to have a single assigned table for both tasks and projects

So, having a user_id field in the tasks table will not allow this

Activity icon

Started a new conversation Eloquent Relationships

Hi everyone.

I am setting up my table relationships in my models and I have come stuck. Below are my 4 tables

User

  • id
  • name

Tasks

  • id
  • title

Project

  • id
  • title

Assigned

  • user_id
  • assignedtable_id
  • assignedtable_type

I have created my morphMany/morphTo relationships (assigned + project) (assigned + tasks) and that is working fine.

I now want to be able to do get the tasks or projects assigned to a user, by doing this:

  • \App\Models\User::find(1)->tasks
  • \App\Models\User::find(1)->projects

What relationship do I set up to connect [user]->[assigned]->[tasks]