Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel white screen when using Redirect Class

I am currently getting a white screen of death when I am trying to redirect my users using the Laravel Redirect class after handling data. If I use the native php-function header("location ...") the application responds correctly and sends the user on its merry way, but using Laravel's Redirect class the site crashes with a white screen of death. I have tried both the Redirect::action and Redirect::to functions, but they are both resulting in the same irritating white screen of death. The laravel.log shows nothing...

Does anyone have any ideas?

Here is the code for the data handler controller class:

<?php
class ManagerLayoutDataController extends BaseController 
{
public function route($action, $moduleID) {
    if(method_exists('ManagerLayoutDataController',$action)) {
        $this->$action($moduleID);
    }
    // Invalid action (method not found)
    else {
        die('Action routing error');
        //return Redirect::to('/');
    }
}

public function updateHeaderBg($moduleID) {
    $image = Input::file('img');
    $user = Auth::user();
    $siteID = $user->getSiteID();

    $layoutDataMessage = null;

    // Validate file upload (NOT FILE CHARACTERISTICS)
    if(Input::hasFile('img') && $image->isValid() && isset($siteID) && $siteID !== "") {
        $res = ManagerFileUpload::uploadImage($siteID, $image);
        if($res->success) {
            $fileName = $res->fileName;
            $dbViewModule = ViewModuleRepository::getModule($moduleID);
            if($dbViewModule->type === DBViewModule::MODULE_TYPE_HEADER) {
                $headerModule = new HeaderModule($dbViewModule);
                $headerModule->updateBgImage($fileName);
                $layoutDataMessage = new LayoutDataMessage(LayoutDataMessage::STATUS_SUCCESS,"");
            }
        }
        else {
            $layoutDataMessage = new LayoutDataMessage(LayoutDataMessage::STATUS_FAIL,$res->message);
        }

    }
    else {
        $layoutDataMessage = new LayoutDataMessage(LayoutDataMessage::STATUS_FAIL, "Bilden kunde inte laddas upp.");
    }

    if($layoutDataMessage != null) {
        return Redirect::action('ManagerLayoutController@main')->with('message',$layoutDataMessage);
        //return Redirect::to('manager/layout/');
        //header('location: */manager/layout');
    }
    else {
        return Redirect::action('ManagerLayoutController@main')->with('message',LayoutDataMessage(LayoutDataMessage::STATUS_FAIL, "Bilden kunde inte laddas upp."));
        //return Redirect::to('manager/layout/');
        //header('location: */manager/layout');
    }
}
}

The Main Controller


<?php
class ManagerLayoutController extends BaseController 
{
    public function main() {
        $user = Auth::user();
        $siteID = $user->getSiteID();

        $moduleComposition = ViewModuleCompositionRepository::getCurrentInWorkModuleComposition($siteID);

        $dbViewModules = ViewModuleRepository::getModulesFromComposition($moduleComposition->id);

        $viewModules = array();

        foreach($dbViewModules as $dbViewModule) {
            switch($dbViewModule->getType()) {
                case DBViewModule::MODULE_TYPE_HEADER:
                    $viewModules[] = new HeaderModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_TEXT_SECTION:
                    $viewModules[] = new TextSectionModule($dbViewModule);
                    break; 
                case DBViewModule::MODULE_TYPE_KEY_METRICS:
                    $viewModules[] = new KeyMetricsModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_SLIDESHOW:
                    $viewModules[] = new SlideShowModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_VACANCIES:
                    $viewModules[] = new VacanciesModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_EMAIL_SUBSCRIPTION:
                    $viewModules[] = new EmailSubscriptionsModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_CO_WORKERS:
                    $viewModules[] = new CoworkersModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_NEWS_SECTION:
                    $viewModules[] = new NewsModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_INSTAGRAM_FEED:
                    $viewModules[] = new KeyMetricsModule($dbViewModule);
                    break;
                case DBViewModule::MODULE_TYPE_SOCIAL_MEDIA:
                    $viewModules[] = new KeyMetricsModule($dbViewModule);
                    break;
            }
        }

        $data = array(
            'siteID' => $siteID,
            'viewModules' => $viewModules
        );

        return View::make('dashboard.pages.manager.layout_main',$data);
    }
}

filters.php


<?php

/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/

App::before(function($request)
{
    //
});


App::after(function($request, $response)
{
    //
});

/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/

Route::filter('auth', function()
{
    if (Auth::guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::guest('login');
        }
    }
});


Route::filter('auth.basic', function()
{
    return Auth::basic();
});

/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
|
*/

Route::filter('guest', function()
{
    if (Auth::check()) return Redirect::to('/');
});

/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/

Route::filter('csrf', function()
{
    if (Session::token() != Input::get('_token'))
    {
        throw new Illuminate\Session\TokenMismatchException;
    }
});


/** Admin pages */
Entrust::routeNeedsRole( 'admin*', 'Admin', Redirect::to('/login'));



/** Manage pages */
Entrust::routeNeedsRole( 'manager*', array('Super Manager','Manager'), Redirect::to('/login'), false );


/**
 * Check view module ownership before editing data
 */

Route::filter('viewmodule.ownership', function($route) {
    $user = Auth::user();
    $siteID = $user->getSiteID();

    $moduleID = $route->getParameter('moduleID');

    // Check that the module with $moduleID belongs to $siteID
    if(ViewModuleRepository::moduleBelongToSite($moduleID, $siteID)) {

    }
    // Unauthorized access
    else {
        die('Filter error');
        //Redirect::to('/');
    }
});

routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', 'FrontController@main');

Route::get('/manager', 'ManagerHomeController@home');
Route::get('/manager/statistics', 'ManagerStatisticsController@main');
Route::get('/manager/resume-manager', 'ManagerResumeController@main');
Route::get('/manager/resume-manager/pending', 'ManagerResumeController@resumesPending');
Route::get('/manager/resume-manager/approved', 'ManagerResumeController@resumesApproved');
Route::get('/manager/resume-manager/rejected', 'ManagerResumeController@resumesRejected');
Route::get('/manager/layout', 'ManagerLayoutController@main');
Route::get('/manager/layout-old', 'OLDManagerLayoutController@main');

Route::post('/manager/layout/data/{action}/{moduleID}/', array('before'=>'viewmodule.ownership', 'uses' => 'ManagerLayoutDataController@route'));

Route::get('/manager/setup', 'ManagerSetupController@setup');

Route::get('/admin', 'AdminHomeController@home');
Route::get('/login', 'UsersController@login');

Route::get('/test', 'TestController@testMail');

// Confide routes
Route::get('users/create', 'UsersController@create');
Route::post('users', 'UsersController@store');
Route::get('users/login', 'UsersController@login');
Route::post('users/login', 'UsersController@doLogin');
Route::get('users/confirm/{code}', 'UsersController@confirm');
Route::get('users/forgot_password', 'UsersController@forgotPassword');
Route::post('users/forgot_password', 'UsersController@doForgotPassword');
Route::get('users/reset_password/{token}', 'UsersController@resetPassword');
Route::post('users/reset_password', 'UsersController@doResetPassword');
Route::get('users/logout', 'UsersController@logout');
like image 929
Erik T Avatar asked Dec 15 '14 09:12

Erik T


1 Answers

Try to add

ini_set('display_errors', 1);

It should at least tell you what is the actual error. This is only for development mode, remove it when you go into production

like image 121
justadev Avatar answered Oct 12 '22 08:10

justadev