I am having troubles with connecting one of my routes to its associate controller function.
Routes file
Route::get('/transaction/export','TransactionController#exporter');
Controller and Function
class TransactionController extends Controller
{
public function exporter(){
dd("works");//-->Not seen :(
return view('admin.transactionExport');
}
}
Link in view
Export
When clicking on the link, the address bar in the browser shows the expected url '/transaction/export', but unfortunately it shows me a blank page. It is as though the function in the Routes file does not link to the proper controller. I have over 30 successful links in this site, and have no idea why this is failing on me right now.
Would appreciate the help. Please inform me if more information is needed to solve this.
Change your route to match the controller:
Route::get('/transaction/exporter', 'TransactionController#exporter');
Your previous route wasn't matching 'exporter'.
Related
it appears that when I created a new route, I receive the 404 error when trying to access the url, which is funny,. because all of my other routes are working just fine.
My web.php looks like so:
Auth::routes();
Route::post('follow/{user}', 'FollowsController#store');
Route::get('/acasa', 'HomeController#index')->name('acasa');
Route::get('/{user}', 'ProfilesController#index')->name('profil');
Route::get('/profil/{user}/edit', 'ProfilesController#edit')->name('editareprofil');
Route::patch('/profil/{user}', 'ProfilesController#update')->name('updateprofil');
Route::get('/alerte', 'PaginaAlerte#index')->name('alerte');
Route::get('/alerte/url/{user}', 'UrlsController#index')->name('editurl');
Route::post('/alerte/url/{user}', 'UrlsController#store')->name('updateurl');
Route::get('/alerte/url/{del_id}/delete','UrlsController#destroy')->name('deleteurl');
The one that is NOT working when I am visiting http://127.0.0.1:8000/alerte is:
Route::get('/alerte', 'PaginaAlerte#index')->name('alerte');
The controller looks like so:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
class PaginaAlerte extends Controller
{
public function __construct() {
$this->middleware('auth');
}
public function index(User $user)
{
return view('alerte');
}
}
I am banging my head around as I cannot see which is the problem. It is not a live website yet, I am just developing on my Windows 10 pc using WAMP.
Moved my comment to a little bit explained answer.
So, in your route collection, you have two conflicting routes
Route::get('/{user}', 'ProfilesController#index')->name('profil');
and
Route::get('/alerte', 'PaginaAlerte#index')->name('alerte');
Imagine that Laravel is reading all routings from top to bottom and it stops to reading next one after the first match.
In your case, Laravel is thinking that alerte is a username and going to the ProfilesController#index controller. Then it tries to find a user with alerte username and returning 404 because for now, you don't have a user with this username.
So to fix 404 error and handle /alerte route, you just need to move the corresponding route before /{username} one.
But here is the dilemma that you got now. What if you will have a user with alerte username? In this case, the user can't see his profile page because now alerte is handling by another route.
And I'm suggesting to use a bit more friendly URL structure for your project. Like /user/{username} to handle some actions with users and still use /alerte to handle alert routes.
The following route catches the url /alerte as well
Route::get('/{user}', 'ProfilesController#index')->name('profil');
Since this one is specified before
Route::get('/alerte', 'PaginaAlerte#index')->name('alerte');
The /alerte will go the the ProfilesController instead.
To fix this change the order of the url definitions or change either of the urls to have nesting e.g. /alerte/home or /user/{user}
Well.
Maybe this is too late, but I have all week dealing with this problem.
I made my own custom.php file and add it in the routes path of my Laravel project, and none of the routes were working at all.
This is how I solved it:
You must remember to edit the RouteServiceProvider.php file located in app\Providers path. In the map() function, you must add your .php file. That should work fine!
To avoid unexpected behaviors, map your custom routes first. Some Laravel based systems can "stop" processing routes if no one of the expected routes rules were satisfied. I face that problem, and was driving me crazy!
I would wish suggest to you declare your URL without the "/", like your first "post" route, because sometimes, I have been got this kind of errors (404).
So, my first recomendation is change the declaration of the route. After that, you should test your middleware, try without the construct, and try again.
Good luck!
working a project with Laravel 5.6.
the problem is, when im going to an url like:
/login
or any other route and specify where it should go, it making its own route and going to another place. no metter if i even clear the code of that blade file.
i have not several routes or blade file that are the same. i have cleared my browser cache, laravel cach, config cache, and the command:
php artisan route:cache
did not worked to clear route cache.
my code example: web.php code
Route::get("/login", "LoginController#login");
Example: LoginController.php code
public function login()
{
return view('/login'); // not going to this path
}
to conclude, it does not read my code :(
need your ideas!
public function login()
{
return view('login');
}
view accepts the view name not the path of the route, If you want go to any route use redirect("/route_name") . But in your case if you redirect to login route again it will throw exception because the login route again calls this function. so you need to pass the view name. for example:
if your login view is in
resources
- views
-login.blade.php
then use above code. or if the login page is in any other folder inside view
it will be like return view("foldername.login")
I have a website in laravel framework and I am trying to add a simple new static page to the admin panel. I have done the following three steps:
Add a template to the views:
app/views/admin/MessageToAll.blade.php
Add the make view code in the controller.
public function MessageToAll(){
return View::make('admin.MessageToAll');
}
Added a route in app/routes.php
Route::get('/admin/MessageToAll',array('as'=>'MessageToAll','uses'=>'AdminController#MessageToAll'));
But when I go to to domain.com/admin/MessageToAll
it gives me a 404 page not found error. Does anyone know what have I missed as I think I have completed all steps for adding this view.
Just put your new route before the /admin/ route (to test it, you want to temporarily make it the very first route in routes.php). The problem is /admin/ or some other similar route executed before your new route.
Also, if you need to just execute static view, you can use something like this (works without using a controller):
Route::get('/admin/MessageToAll', function (){
return View::make('admin.MessageToAll');
});
in routes add:
Route::get('/admin/MessageToAll','yourController#yourMethod');
Im new to laravel, but im trying to integrate an existing php script that I have into the laravel app. I understand everything happens in a MVC based architecture. However,im trying to link this page into the header page whose path is application/view/templates/header.php.
For example, there is a controller present in application/controller/LoginController.php and that has a function called public function index() and the way which it is called from headertemplate is:
<li <?php if (View::checkForActiveControllerAndAction($filename, "login/register")) { echo ' class="active" '; } ?> >
Register
</li>
<li>
Administrator Login
</li>
As you can see when i try to call a script which is in the root directory, called admin.php it gives me a 404 - Page not found.
Im really struggling I hope someone can help me figure out the problem. A 404 error is never fun as it is only a tiny error.
If you really want to run a basic PHP script then you can always chuck it in the public directory or try routing it from somewhere else. You're using it as a login script for admins so I would highly suggest just reprogramming it to be a part of your laravel site. Totally up to you though, this may not be the best answer but it will work.
I would suggest do it step by step
Route
In your /app/Http/routes.php
Route::get('/login/register', 'LoginController#index');
Controller
Let make sure you create a LoginController.php in /app/Http/Controllers/
Function
In your /app/Http/Controllers/LoginController.php , create a function call index to return a view.
public function index(){
return view('templates.header); // <-------- /templates/header.blade.php
}
View
inside your /resources/views/templates create header.blade.php
Place all the HTML code needed in it
Test
go to http://localhost/login/register
should load what you place in side your header.blade.php
You shouldn't get 404 anymore.
I'm new to FuelPHP and I did a little coding with it! What I did was create a simple controller and created two methods. One for action_index() and the other is action_add().
the code is given below. Views are already in the app\views\ folder.
class Controller_Student extends Controller
{
public function action_index()
{
return Response::forge(View::forge('index'));
}
public function action_add()
{
return Response::forge(View::forge('select'));
}
}
I've set the root to this controller class. When I run the application the index works fine and loads the directed view. But when I give the following URL
http://localhost/project/public/add/
the method doesn't get called! A 404 error is give saying
You can see this page because the URL you are accessing cannot be found.
What Am I doing wrong here. I've gone through every documentation, tutorial I find but I shouldn't get this type of an error. Please help me.
Below is the routing file code :
return array(
'_root_' => 'student', // The default route
'_404_' => 'welcome/404', // The main 404 route
);
You've set the root to student controller, but that doesn't mean all traffic goes through that controller. Try visiting:
http://localhost/project/public/student/add/