laracasts_asker

Member Since 11 Months Ago

Experience Points
1,000
Total
Experience

4,000 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
0
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.

  • Community Pillar

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

Level 1
1,000 XP
Apr
13
22 hours ago
Activity icon

Replied to Can App\Exceptions\Handler Log Last SQL Querry?

I found out what I actually want: To make eloqent throw a normal exception that is handled by the database handler if there is a database timeout.

Activity icon

Started a new Conversation How To Configure Eloqent To Throw Exception On Database Timeout?

If database is not availalbe I get "504 Gateway Time-out The server didn't respond in time.". How do I configure eloquent so a database timeout throws a regular exception? (so the handler can show my standard error page)

I tried to set the PDO options to PDO::ERRMODE_EXCEPTION in config/database.php but it did not work.

        'mysql' => [ 
                'driver' => 'mysql', 
                'host' => env('DB_HOST', 'forge'), 
                'port' => env('DB_PORT', '3306'), 
                'database' => env('DB_DATABASE', 'forge'), 
                'username' => env('DB_USERNAME', 'forge'), 
                'password' => env('DB_PASSWORD', ''), 
                'charset' => 'utf8', 
                'collation' => 'utf8_unicode_ci', 
                'prefix' => '', 
                'strict' => false, 
                'engine' => null, 
                'options'   => [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,]
                ],
Apr
09
4 days ago
Activity icon

Started a new Conversation Exception Handler Can't Handle Database Connection Timeout

I'm opening this view when database is not accessible:

<?php
$result = DB::select('SELECT * FROM `list` LIMIT ?', [1]);
?>
<html> <body> ok </body></html>

error shown in logs:

[2021-04-09 15:32:40] production.ERROR: SQLSTATE[HY000] [2002] Connection timed out (SQL: SELECT * FROM `list` LIMIT 1) (View: /opt/app-root/src/resources/views/err1.blade.php) {"exception":"[object] (Facade\Ignition\Exceptions\ViewException(code: 0): SQLSTATE[HY000] [2002] Connection timed out (SQL: SELECT * FROM `tokenliste` LIMIT 1) (View: /opt/app-root/src/resources/views/err1.blade.php) at /opt/app-root/src/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)
[stacktrace]

this is the render funciton from my handler.php:

public function render($request, Throwable $exception)
    {
     return response()->view('errors.404');    
    }

Expected behaviour: 404 Error Page is shown. Observed behaviour: "504 Gateway Time-out The server didn't respond in time. " is shown.

What I have tried: I tried different Database operations like DB::connection()->getDatabaseName() or DB::connection()->getPdo(); but they all return the 504 Gateway Error if the Database is offline. If the Database is online, all works fine. Other errors like just writing asdf in a php code line, correctly show the 404 error page. I also tried to catch the error with the following, but no change in results:

try
{
   DB::select('SELECT * FROM `tokenliste` LIMIT ?', [1]);
} 
catch(\PDOException $error)
{
   return $error->getMessage();
}

thanks in advance :)

Activity icon

Replied to (non-local) Database Operation: Try/catch Fails (504 Timeout)

"Or you could catch a PDOException and return a friendly message." "There is also QueryException" So it makes a difference if I do catch (\Exception $e) or catch (\PDOException $e) ?

try {
$result = DB::select('SELECT * FROM `tokenliste` LIMIT ?', [1]);
}
catch (\PDOException $e) {
abort(404);
}

because this did not work either.

additional info on what I have tried: I tried different Database operations like DB::connection()->getDatabaseName() or DB::connection()->getPdo(); but they all return the 504 Gateway Error if the Database is offline. If the Database is online, all works fine. Other errors like just writing asdf in a php code line, correctly show the 404 error page. I also tried to catch the error inside the code with try / catch but that does not change the results.

Apr
08
5 days ago
Activity icon

Started a new Conversation (non-local) Database Operation: Try/catch Fails (504 Timeout)

<?php
try {
        $result = DB::select('SELECT * FROM `mytable` LIMIT ?', [1]); 
        }
        catch (\Exception $e)
        {
        abort(404);
        }
?>
<html>
    <body>
        <h1> all ok</h1>
    </body>
</html>

Observed behaviour on opening this view : "504 Gateway Time-out The server didn't respond in time. " is displayed when Database is not online. Desired behaviour: 404 Error Page is called, if Database is not online. "all ok" is shown when Database is online.

I suspect this has someting to do with the Database running on another URL (in an openshift/ kubernetes cluster) and not under localhost. How can I try/catch Database operations if my Database is running under another URL?

Activity icon

Started a new Conversation Can App\Exceptions\Handler Log Last SQL Querry?

Hi guys, is there any way to log the last SQL Querry by the App\Exceptions\Handler in an extra channel? (Would be super usefull, because some of my Database operations could throw an error, depending on the database state, thanks.)

Apr
07
6 days ago
Activity icon

Replied to How To Do Custom Error Pages For Different Database Errors?

OR I could find a way to log SQL querries in the exception handler report function and then show the custom error page. Do you know how do I tell the report function in the Exception Handler to log the failed SQL querry in an extra channel? (You can answer here: https://laracasts.com/discuss/channels/laravel/if-a-database-operations-fails-how-to-log-the-failed-sql-querry)

Activity icon

Started a new Conversation If A Database Operations Fails, How To Log The Failed SQL Querry?

If a database operation (like delete, insert, select, no connection) fails, how do I tell the report function in the Exception Handler to log the failed SQL querry in an extra channel?

thanks in advance, laracasts_asker

Activity icon

Replied to How To Do Custom Error Pages For Different Database Errors?

Ok thanks, so even If I just tell users: This token database is empty that would be too much Information, right? Because now they now there is a token database and so on ...

ok, so I could do a try / catch where I log the specific error in a channel and sent an email, then call an abort and show the custom error page.

Activity icon

Started a new Conversation How To Do Custom Error Pages For Different Database Errors?

I know from the docs Laravel allows custom error messages, but did not found if this is possible: I would like to have one custom error page when my Database is not accessible, one when a select is not happening, and one when a delete is not working.

Do you know how that would work? If not, would it be possible to just have one custom error page when a Database Operation fails and have the SQL querry mailed to me, so I know what's going on?

Apr
06
1 week ago
Activity icon

Replied to Return View Works From Routes.php, But Not From Included Function

"will be too late in the Request Lifecycle to be useful" could you explain more what you mean? You mean this is the reason the view does not show?

Ok so I looked into the error handling link. Would these two options would work? A) I could show a specific page when database errors occur. Would the logs then tell me which database operations failed? Because I would like to know if it's an insert, a delete or a select.

B) I could do try / catch (like I do now) and then use abort() function where I specify if it was a ninsert, a delete or a select, right?

Mar
31
1 week ago
Activity icon

Replied to Return View Works From Routes.php, But Not From Included Function

or you mean I should just rely on the logs and not do too specific error messages to users? I mean it is important to know what type of database operation failed (connection, table empty, etc.. ) and I am not sure if that would be obvious from the standard logs.

Activity icon

Replied to Return View Works From Routes.php, But Not From Included Function

Hi, thanks for your answer. That would be a lot of code but to sum it up: When I open my welcome.blade.php, there is a an include_once(function.php). A function from function.php is called to check if the database is accessible:

try {
    $db=DB::connection()->getPdo();
	}
	catch (\Exception $e) 
	{

		errorinfo(0);
}
	return($db);		 
}

If it is not accessible, errorinfo(0) is called.

function errorinfo($id)
{
    return view('message')->with('success', 'message');
exit();
    return;
}

I know the return view is the error due to testing. So what I want to accomplish is show people an error page when the database connection is not working. (in other circumstances I want to show that page when a certain database opperation is not possible for example a token database is empty)

Activity icon

Started a new Conversation Return View Works From Routes.php, But Not From Included Function

Calling this from routes.php works: return view('error_message')->with('success', 'success message'); but running the same code with include_once( function.php) doesn't show the view. Tips? Thanks in advance :)

Activity icon

Replied to How Do I Return A View With A Custom Message?

thanks martin, it worked, you get an award for the quickest response ever :) I also will name: laravel custom error page and custom error message laravel for potential searchers (most articles on this are old).

Activity icon

Started a new Conversation How Do I Return A View With A Custom Message?

The message should be specified upon calling the view. This should work, but it doesn't:

return view('message')->with('success', 'Test Message'); and then showing the message in the view with: {!! \Session::get('success') !!} Tips? Thanks in advance :)

Mar
30
2 weeks ago
Activity icon

Replied to Directing To A Page With An Error Message (Laravel 7)

hi Charizard, thanks for the reply. Like suggested I put the return view in my routes web.php:

Route::get('/', function () {
    return view('message')->with('success', 'Test MEssage');
});

Here's my message.blade.php:

<html>
    <body>
        <div class="alert alert-success">
        <ul>
            <li>{!! \Session::get('success') !!}</li>
        </ul>
    </div>
    </body>
</html>

But it does'nt show "Test Message" when opening the message view. Do you know what I'm doing wrong?

Mar
29
2 weeks ago
Activity icon

Started a new Conversation Directing To A Page With An Error Message (Laravel 7)

From a php file inluded in a view and from the controller I do verious catch / try. From there I would like to redirect to an error view that shows a text that was specified in the redirect. How do I do that?

(What I found is: return redirect('message')->with('success', 'Test MEssage'); But that did not show my message.blade.php view.)

Mar
19
3 weeks ago
Activity icon

Replied to Best Practice To Implement Custom Error Messages?

the way it is meant to be is: I don't do try / catch inside my normal code, I let those errors occur, because they will then be processed by the exception/Handler.php and here I decide what to do with it, right?

Activity icon

Replied to Best Practice To Implement Custom Error Messages?

ok thanks for your tip. At the point where I want to exit I put this in the code abort(403, 'my error message.'); then in the exption handler:

if ($exception instanceof HttpResponseException) {
        Flash::error($exception->getMessage());
    }

Would this work? And would this open a new view or stay in the old view?

Activity icon

Replied to Best Practice To Implement Custom Error Messages?

When my webpage openes, it checks if a database connection is there. If there is no connection, there should be a message to the users. Also when form input is made and something does not work (database connection, no token, ...), an error message should be displayed.

Mar
18
3 weeks ago
Activity icon

Started a new Conversation Best Practice To Implement Custom Error Messages?

Before Laravel, I had used exit('my error message'). Now that exit() would be handled by the exception/Handler.php render function, right?

What's best practice with laravel to get those error messages back?

Mar
16
4 weeks ago
Activity icon

Replied to Confusing Error Handling Of Welcome Blade

the database is on another server. Might this confuse the error behaviour in this part?

try {
    $db=DB::connection()->getPdo();
	}
Activity icon

Replied to Confusing Error Handling Of Welcome Blade

thanks for your suggestion and it's good idea. To check I created a simple error view that should do no database checks:

@extends('errors::illustrated-layout')

@section('code', '404')
@section('title', __('Page Not Found'))
@section('image')
    <div style="background-image: url({{ asset('/svg/404.svg') }});" class="absolute pin bg-cover bg-no-repeat md:bg-left lg:bg-center">
    </div>
@endsection
@section('message', __('Sorry, the page you are looking for could not be found.'))

but the view is not displayed, the old one is displayed:

504 Gateway Time-out
The server didn't respond in time. 

If you look above, right after the email I am doing a trigger_error, but that is not shown. It's really strange, because I get the email, so I know this part of the code gets callled.

But why is the trigger_error not displayed?

Activity icon

Started a new Conversation Confusing Error Handling Of Welcome Blade

.env : APP_DEBUG=true

config/app.php :'debug' => env('APP_DEBUG', true),

app/Exceptions/Handler.php :

public function render($request, Throwable $exception)
    {
      return view('error');
    }

This function that checks database connection gets called on every view and may be a cause for error?

try {
    $db=DB::connection()->getPdo();
	}
	catch (\Exception $e) 
	{
		\Mail::to("[email protected]")->send(new \App\Mail\custommail());	
// mail gets sent, above error gets shown when I open welcome blade
		trigger_error("Database not accessbile", E_USER_WARNING);
	    exit();
		exit('Database not accessible. ' . mysqli_connect_error() .   config('mail.errorcall'));
		return (false);	
	}
	return($db);		 
}

desired output when database is not connected: show error view, but instead I get just this:

504 Gateway Time-out
The server didn't respond in time. 
Nov
13
5 months ago
Activity icon

Replied to Unable To Find Socket Transport Starttls

changing in the .env from starttls to tls did it for me :)

Nov
12
5 months ago
Activity icon

Awarded Best Reply on Database-to-laravel-connection Fails, Tips To Diagnose?

@automica thanks it works now, the reason was the wrong mysql version.

Nov
11
5 months ago
Activity icon

Replied to Database-to-laravel-connection Fails, Tips To Diagnose?

@automica thanks it works now, the reason was the wrong mysql version.

Nov
10
5 months ago
Activity icon

Replied to Database-to-laravel-connection Fails, Tips To Diagnose?

@automica thanks for your reply, this system is containerized (like docker) with openshift cluster. If I type

mysql -u root -p -h mysqltest

in terminal of another container and provide the password I specified in laravel, I can connect, so the database seems to work in theory.

I'm new to error logging, where whould I find those? (looked here, https://laravel.com/docs/5.5/errors but don't undestand where it is)

Activity icon

Started a new Conversation Anything To Look Out For When Containerizing Your Local Laravel Development App Using Openshift?

... especially regarding composer or database connections? (Because when you containerize, you create one laravel pod from source code from which openshift will run composer.)

Activity icon

Started a new Conversation Database-to-laravel-connection Fails, Tips To Diagnose?

config in .env File:

DB_CONNECTION=mysql
DB_HOST=mysqltest
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=password

config in config/database.php

'mysql' => [ 
                'driver' => 'mysql', 
                'host' => env('DB_HOST', 'forge'), 
                'port' => env('DB_PORT', '3306'), 
                'database' => env('DB_DATABASE', 'forge'), 
                'username' => env('DB_USERNAME', 'forge'), 
                'password' => env('DB_PASSWORD', ''), 
                'charset' => 'utf8', 
                'collation' => 'utf8_unicode_ci', 
                'prefix' => '', 
                'strict' => false, 
                'engine' => null, 
                ],