i want to open a new window with passing id of students shows error in new window - laravel

I am successfully loading a page in a new window using target="_blank",but the problem is the new window is loading with an error NotFoundException, when i try to pass id from the current window to new window
{{$stud->name}}
Route::get('search/display/{$id}','studcontroller#searchstud');
.....

NotFoundException is occurred for the routes not declared.
Check if you have created a route in routes.php.
Also verify the method to be GET.
If you have cached your routes earlier, try refreshing the route cache by using the command php artisan route:cache.
NOTE: This route cache command will work only if you are not using any
closure route.
One more thing you can do to get proper link is, use Url::to() method supported by Laravel Illuminate.

You're not closing the href attribute value. So, add ":
{{$stud->name}}

Like #Alexey mentioned you where missing quotes, but you will also have to send the id parameter
{{$stud->name}}

Related

How to stop the GET method is not supported for this route from showing?

I have a working Laravel project with loads of different routes.
I'm currently testing it and one of my tests was to check if a user were to use a delete or post route from the URL. I didn't know what the application would do honestly and it outputted the typical:
The GET method is not supported for this route. Supported methods: DELETE
which I have seen a million times. Is there a way to stop this error from coming up and instead output an error screen or simply redirect to a different view?
The error message:
The GET method is not supported for this route. Supported methods: DELETE.
should only appear when your Laravel site has APP_DEBUG set to true (in the .env file).
When APP_DEBUG is set to false as it should always be in on a live site, then the user will be shown a 404 error page instead.
You can easily test this by adding the following code to your routes file:
Route::delete('test', function() {
return 'You should never see this text when viewing url via a GET request';
});
May be u didn't noticed but ur form tag method attribute and route definition is different

Dompdf Laravel Test

I am having problems resolving this issue. I want the user to be able to download a report when pressing the button. I keep on getting Action not defined, and if I change my route it will simply not load the app.
Any help would be appreciated.
/************View***************/
<button>Download PDF</button>
/*************Controller****************/
public function pdf($id){
$report=Report::findorFail($id);
$pdf = PDF::loadView('reports.show', compact('report'));
return $pdf->download('server_report.pdf');
}
You need to have your action defined in a route.
For example:
Route::get('pdf','ReportController#pdf');
Also, make sure that if ReportController has a resource route then the pdf route goes above it.

Session return null anyway

My project is using three different services and now I never can get sessions values, I've tried the laravel site tutorial and fallowing link question :
Laravel - Session returns null
But none of them worked!
In the first, i used this library:
use Session;
In a controller class :
$result = SocketHelper::sendRequest($req);
Session::put('uuid', $result->uuid);
Session::save();
Session::put('userId', $result->userID);
return Redirect::route('login_step_two');
In an other method :
$uuid = Session::get('uuid');
$userId = Session::get('userId');
But these are null! does I have to use cookie?
I recently upgrade to laravel 5.4
Please help me! It's made me confused!
Thanks.
Try saving Session explicitly like this, give it a try it worked for me, hope same for you.
Session::put('test_session', 'test message');
Session::save();
And retrieve it like this
echo Session::get('test_session');
And forget it like this:
Session::forget('test_session');
Session::save();
I understood the null result was becouse I was posting the value of $request to an other template and it was changed it the way :))) !
so easy to know !
Have you properly upgraded to laravel 5.4?
Laravel Docs
Sessions
Symfony Compatibility
Laravel's session handlers no longer implements Symfony's SessionInterface. Implementing this interface required us to implement extraneous features that were not needed by the framework. Instead, a new Illuminate\Contracts\Session\Session interface has been defined and may be used instead. The following code changes should also be applied:
All calls to the ->set() method should be changed to ->put(). Typically, Laravel applications would never call the set method since it has never been documented within the Laravel documentation. However, it is included here out of caution.
All calls to the ->getToken() method should be changed to ->token().
All calls to the $request->setSession() method should be changed to setLaravelSession().
Do you still have the rights to write session files in php session directory ?
Check the path returned by session_save_path() and check if your php user has the rights to write in it, check also if there is files in the directory and what are their creation date.

Laravel 4: Redirecting when invalid route

I am trying to treat the invalid requests on my Laravel app, something like redirecting to the root will work just fine, but I can't manage to do it.
In the documentation and around stackoverflow I saw this is always the solution:
App::missing(function() {
# handle the error
});
I thought that would just go to the routes file but no. Then I saw in some post it should be in the app/start/global.php file but it still didn't work.
In the docs it says I can "register an error handle". Is that what I should do? What does this mean? What should I do?
Ultimately this can be put anywhere, but app/start/global.php is probably the best place for it.
App::missing(function($exception)
{
return Response::view('errors.missing', array(), 404);
});
Try putting this in there. In fact, if you've just setup a fresh installation, you should already have one there.
Here is how you can register an error handler, like so;
App::error(function(Exception $exception, $code)
{
//Now you can check for different exceptions and handle each on their own way.
}
This will be for PHP general Exception class which will make all exceptions go here, but you can change Exception to the specific Exception class of you own and handle it accordingly.
App::missing will generally be called when a page within your site has not been found, allowing you to show a default page for when users have found a non existing page. So if you are wanting to handle missing pages, use App::missing else use App::error.

Laravel 4 - changing resource root routing path

In a Laravel 4 installation, Using Jeffrey Way's Laravel 4 Generators, I set up a 'tweet' resource, using the scaffolding command from his example:
php artisan generate:scaffold tweet --fields="author:string, body:text"
This generated the model, view, controller, migration and routing information for the tweet type. After migrating the database, visiting http://localhost:8000/tweets works fine, and shows the expected content.
The contents of the routes.php file at this point is:
Route::resource('tweets', 'TweetsController');
Now I would like to move the url for tweets up one level into admin/tweets, so the above url should become: http://localhost:8000/admin/tweets. Please note that I am not treating 'Admin' as a resource, but instead just want to add it for hypothetical organizational purposes.
Changing the routes.php file to:
Route::resource('admin/tweets', 'TweetsController');
Does not work, and displays the following error:
Unable to generate a URL for the named route "tweets.create" as such route does not exist.
Similarly when using the following:
Route::group(array('prefix' => 'admin'), function() {
Route::resource('tweets', 'TweetsController');
});
As was suggested in this stackoverflow question.
Using php artisan routes reveals that the named routes also now have admin prefixed to them, turning tweets.create into admin.tweets.create.
Why is the error saying that it cannot find tweets.create? shouldn't that automatically be resolved (judging by the routes table), to use admin.tweets.create?
How can I change my routing so that this error no longer occurs?
I just tested with new resource controller and it works fine for me.
The problem is not with the Route, its with the named routes used in your application.
check your view files there are link to route like link_to_route('tweets.create', 'Add new tweet'), this is creating the error because when you add admin as prefix tweets.create doesn't exists so change it to admin.tweets.create every where, in your controller also where ever named route is used.

Resources