Here is my routes file:
Route::get('/', ['as' => 'home', 'uses' => function() {
return view('pages/home');
}]);
Route::get('/companies', ['uses' => 'CompaniesController@index', 'as' => 'companies']);
Route::post('/companies/search', ['uses' => 'CompaniesController@search', 'as' => 'companies.search']);
Route::get('/companies/{symbol}', ['uses' => 'CompaniesController@view', 'as' => 'companies.view']);
Here is my companies controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\CompanySearchRequest;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use \SoapClient;
use Session;
use Redirect;
class CompaniesController extends Controller
{
public function index()
{
$client = new SoapClient(config('mannisland.wsdl_url'));
try {
$results = $client->getCompanies([
'username' => '********',
'password' => '********'
]);
} catch(\Exception $ex) {
var_dump($ex->faultcode, $ex->faultstring, $ex->faultactor, $ex->detail);
}
$companies = [];
foreach($results as $company) {
$companies[$company->symbol] = $company->name;
}
return view('companies/index')->with('companies', $companies);
}
public function search(CompanySearchRequest $request)
{
return redirect(route('companies.view', $request->symbol));
}
public function view($symbol)
{
$client = new SoapClient(config('mannisland.wsdl_url'));
try {
$results = $client->getDirectorsBySymbol([
'username' => '********',
'password' => '********',
'symbol' => $symbol
]);
} catch(\Exception $ex) {
return Redirect::route('companies')->with('message', $ex->faultcode.' '.$ex->faultactor);
}
dd($results);
return view('companies/view')->with('company', $company);
}
}
In my template I have the following code:
{!! (Session::has('message')) ? '<div class="alert alert-danger"><strong>Error!</strong> '.Session::get('message').'</div>' : '' !!}
As you can see within the view() method if an exception is caught I do a redirect with an error message which I am trying to output in the view. No matter what I try though the message won't appear. What am I doing wrong?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire