laravel DB::connection()->getPdo()::PARAM_STR not working - laravel-5

The function getPdo() with PARAM_STR in laravel
DB::connection()->getPdo()::PARAM_STR
is working fine with php 7.0.0 but not working with php 5.6.16 or lesser versions. How can I get the PARAM_STR from PDO instance in laravel with php 5.6.16 or less?
I have tried
DB::connection()->getPdo()->PARAM_STR
but not working for me..

The solution which worked for me is this..
static function db ()
{
try {
$db = DB::connection()->getPdo();
}
catch (PDOException $e) {
self::fatal(
"An error occurred while connecting to the database. ".
"The error reported by the server was: ".$e->getMessage()
);
}
return $db;
}
By calling..
$db=self::db();
$db::PARAM_STR
I got it solved. All inside class & method

Related

Handle Laravel QueryException and show custom error page using XAMPP

I'm locally developing a Laravel website using XAMPP. To make the site works, I obviously have to turn on the Apache service and it does work indeed. What I want to be able to do is to handle the case when the apache server is down and show my error message. I mean, if I purposely turn off Apache, I receive this error Exception:
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] Connection refused.
(SQL: select * from `users` where `email` = test#yahoo.it limit 1)
This is the image: https://pasteboard.co/JegwA2Y.png
Here comes my question. How can I show for example one of my custom error pages instead of this default Laravel QueryException? Where to catch the exception?
Even though my app is not on production mode, I'd still like to show the errors properly.
Thanks!
You must change render method in App\Exceptions\Handler class. You can read details in documentation.
Sample Code:
public function render($request, Throwable $exception)
{
// Custom render.
if ($exception instanceof QueryException) {
return response()->view('errors.query', [], 500);
}
// Add extra custom render.
if ($exception instanceof ModelNotFoundException) {
return response()->view('errors.not_found', [], 500);
}
// Default render.
return parent::render($request, $exception);
}

Backup failed in Browser, works with php artisan backup:run

I am new to Laravel, I have created a driver with the create function to create backups to my database on xampp server, but my problem is that in the browser it does not show me any errors but no backup of my database is created. Help me please. Here I leave the code of my create function.
public function create()
{
try {
// start the backup process
Artisan::call('backup:run', ['--only-db'=> true,'--disable-notifications'=> true]);
$output = Artisan::output();
// log the results
Log::info("Backpack\BackupManager -- new backup started from admin interface \r\n" . $output);
// return the results as a response to the ajax call
Alert::success('Nuevo Backup Creado');
return redirect()->back();
} catch (Exception $e) {
Flash::error($e->getMessage());
return redirect()->back();
}
}
Artisan::call('backup:run'); does not work use queue instead of call
working syntax
Artisan::queue('backup:run');

Laravel : route not hitting controller

Route::any('mobileLogin', ['as' => 'mobileLogin', 'uses' =>
'App\Controllers\LoginController#mobileLogin']);
For some reason my perfectly working route has stopped working and a "whoops" error is being shown using app/views/error-page.blade.php
Here is the controller function:
public function mobileLogin()
{
try
{
Log::info('----------------');
Log::info('Inside mobileLogin');
}
catch (\Exception $e)
{
Log::info('*********** ERROR**************');
Log::info('Message: ' . $e->getMessage());
Log::info('Trace String : ' . $e->getTraceAsString());
Log::info("*********** END of ERROR *************");
}
}
The /app/storage/logs/laravel.log don't show any error, hence trying to find what exactly went wrong.
In my config/app.php debug is set to true as well.
I've put log messages in my controller function as well, but it's failing before it even reaches there !
How does one debug this ?
If Laravel framework isn't routing to the controller itself, then where can I dig for the issue ?
Found the issue - it was an error in one of the php files itself.
I expected for a syntax error an error would show in the laravel.log, but no !
There is another error.log at the base of the app, which luckily had it !

Laravel 5.4 - Adldap - Call to undefined method Adldap\Adldap::search()

I have an issue with my Laravel installation and the use of Adldap...
The error message I receive :
FatalThrowableError in UserCreationController.php line 100:
Class 'App\Http\Controllers\Adldap' not found
I have installed/deployed Adldap according to the documentation and it is working when I call it from some other location.
Working stuff :
Route::get('ldap', function() {
$results = Adldap::search()->where('ou', 'ends_with', ' Users')
->orWhere('ou','not_contains', 'Production')
->sortBy('ou', 'asc')
->get();
foreach ($results as $result) {
dump ($result->ou);
}
The page displays the dump correctly. All is fine.
Not working stuff (yields error code listed above).
Route calling a Controller...
Route :
Route::get('newuser', 'UserCreationController#GetUserOrganizationalUnits');
Controller :
public function GetUserOrganizationalUnits()
{
$results = Adldap::search()->where('ou', 'ends_with', ' Users')
->orWhere('ou','not_contains', 'Production')
->sortBy('ou', 'asc')
->get();
return view('newuserform',compact('results'));
}
Why is it working from the web php with the routes directly but not from the called Controller?
I already try adding explicitely the following as well...
use Adldap\Contracts\AdldapInterface;
The facade is declared and it works in the web routes without even calling this...
Can you please help ?
Thanks.
I think you forgot to include the Facade
Add: use Adldap; in your UserCreationController.php
You'll also need to have this in your UserCreationController to get this working with the "use Adldap\Contracts\AdldapInterface;" approach:
protected $adldap;
public function __construct(AdldapInterface $adldap)
{
$this->adldap = $adldap;
}
Or implement the facade in your config/app.php:
'Adldap' => Adldap\Laravel\Facades\Adldap::class

Laravel default route to 404 page

I'm using Laravel 4 framework and I've defined a whole bunch of routes, now I wonder for all the undefined urls, how to route them to 404 page?
In Laravel 5.2. Do nothing just create a file name 404.blade.php in the errors folder , it will detect 404 exception automatically.
Undefined routes fires the Symfony\Component\HttpKernel\Exception\NotFoundHttpException exception which you can handle in the app/start/global.php using the App::error() method like this:
/**
* 404 Errors
*/
App::error(function(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception, $code)
{
// handle the exception and show view or redirect to a diff route
return View::make('errors.404');
});
The recommended method for handling errors can be found in the Laravel docs:
http://laravel.com/docs/4.2/errors#handling-404-errors
Use the App::missing() function in the start/global.php file in the following manner:
App::missing(function($exception)
{
return Response::view('errors.missing', array(), 404);
});
according to the official documentation
you can just add a file in: resources/views/errors/
called 404.blade.php with the information you want to display on a 404 error.
I've upgraded my laravel 4 codebase to Laravel 5, for anyone who cares:
App::missing(function($exception) {...});
is NO LONGER AVAILABLE in Laravel 5, in order to return the 404 view for all non-existent routes, try put the following in app/Http/Kernel.php:
public function handle($request) {
try {
return parent::handle($request);
}
catch (Exception $e) {
echo \View::make('frontend_pages.page_404');
exit;
// throw $e;
}
}

Resources