I created a resource controller. The problem is when I code a route in my view, the browser displays Route [course] not defined.
I run the php artisan route:list command and I realize that the route does not exist in the route list.
The controller method
public function index()
{
$courses = Course::where('user_id', Auth::user()->id)->paginate(10);
return view('teacher.teachercourse.courses', compact('courses'));
}
The web.php code
Route::get('course', 'CoursesController#index')->name('course');
Route::get('course', 'CoursesController#create')->name('course.create');
The link
<li>Courses</li>
As both routes are get you can't use the same uri:
change the uri example:
Route::get('courses', 'CoursesController#index')->name('courses.index');
Route::post('course/create', 'CoursesController#create')->name('course.create');
Related
I have unique problem. I already create Route on web.php, on Controller, and Blade. and working on my localhost. but after publish to real server, I jus got error Action url\controller#function not define. this is my code.
Route::get('/timetableschedule', 'ManagementController#EmployeeTimeTable');
this is my web.php
public function EmployeeTimeTable(Request $request){
$session = $request->session()->get('user.id');
$companysession = $request->session()->get('user.location');
$locationdata = DB::table('company')
->join('companyrole','companyrole.company_id','=','company.Company_id')
->join('users','users.id','=','companyrole.user_id')
->where('users.id',$session)
->get();
$userlist = db::table('users')
->join('companyrole','users.id','companyrole.user_id')
->where('companyrole.company_id',$companysession)
->whereNotNull('users.NPK')
->select('users.id','users.name','users.NPK')
->orderby('users.name')
->get();
$timesetting = db::table('time_leaving')
->where('company_id',$companysession)
->get();
$leaveschedule = db::table('employee_leaving')
->join('users','employee_leaving.user_id','users.id')
->where('employee_leaving.company_id',$companysession)
->select('employee_leaving.leaving_date','users.name')
->get();
return view('Management.employeetimetable',['location'=>$locationdata,'UserList'=>$userlist,'ListTimeSet'=>$timesetting,'LeavingSchedule'=>$leaveschedule]);
}
this is my controller
<li>
<a href="{{action('ManagementController#EmployeeTimeTable')}}" class="dropdown-item">
<p>Employee Timetable</p>
</a>
</li>
and this is code on blade to call controller#function
this step same as another controller, web, and blade.php. but, just for this rout get me a trouble. thank you
You have a problem with your route cache, simply do this:
php artisan cache:clear
php artisan route:cache
if you want to do same on the server you can define a route in web.php for that like this:
Route::get('/clear/route', 'ConfigController#clearRoute');
and make ConfigController.php like this
class ConfigController extends Controller
{
public function clearRoute()
{
\Artisan::call('route:clear');
}
}
and then go to that route on server example http://your-domain/clear/route
If your controller is on a subfolder, and not in app\Http\Controllers you will need to provide the fully qualified class name of the controller to the action helper :
action('App\Http\Controllers\Admin\ManagementController#EmployeeTimeTable')
by default action helper will look for : App\Http\Controllers\ManagementController
note that this syntax will not work as you might expect :
action('Admin\ManagementController#EmployeeTimeTable')
because laravel will not add App\Http\Controllers if there is a \ in the action name parameter
This error is comeup while i working on laravel 8
Route [product.details] not defined. (View: C:\xampp\htdocs\ecommerce\resources\views\livewire\shop-component.blade.php)
here is the route i made Route Page web.php
Route::get('/product/{slug}',DetailsComponent::class)->name('product.details');
this is line of view where i want that route View Page shop-component.balde.php
<a href="{{route('product.details',['slug'=>$product->slug]) }}" title="{{$product->name}}">
and this one is the Details Component code
namespace App\Http\Livewire;
use Livewire\Component;
class DetailsComponent extends Component
{
public $slug;
Public function mount($slug){
$this->slug = $slug;
}
public function render()
{
$product = Product::where('slug', $this->slug)->first();
return view('livewire.details-component',['product'=>$product])->layout('layouts.base');
}
}
I think this php code doesnot get route of product.details at the same time i create middleware file and define a different route in it this route is working in this page but not Product.details.
Kindly help me i am stuck from 1 week here
You can use
php artisan route:list
to show a list of registered routes - make sure it shows up there. If it doesn't, use
php artisan route:clear
to clear Laravel's route cache
It does not work because of your route. It's not write in the correct way. You have first to make your DetailsComponent::class is bracket then you have to give the name of the method you want to use in this class.
Route::get('/product/{slug}', [DetailsComponent::class, 'method name'])->name('product.details');
I have just created one of about view in view/about.blade.php, and I am accessing this from localhost/myproject/public/about, but it's not working.
However, localhost/myprojects/public/ is working fine; about view has been created on same parameters as welcome by default in Laravel.
Firstly the information is not sufficient to say anything.Please provide your route.Also its important how you are running your project ,is it via Xampp(or Lampp whatever is there) or "php artisan serve"
but looking from your working directory "localhost/myprojects/public" I guess its not by the command . Try localhost/myprojects/public/about.blade.php or run it by php artisan serve and try route localhost:8000/about
Have you added particular routing to web.php file?
Route::get('about', function () {
return view('about');
});
https://laravel.com/docs/5.7/routing
Which error are you getting?
404 - Not found
Route::get('/about', function () {
return view('about');
});
Check routes
php artisan route:list
Laravel is a MVC Framework, Which means You Have a Controller which procede some logic when some request come in and interact with the model if need, after that the controller return some view.
And because you whan to acccess your view file, you must past through controller, and that controller will render the view. Because the views folder is not in the \public dicretory as subdirectory you can't access to It with url like localhost/myproject/public/about even if you get access to it, you will not get HTML, you'll get some plain text with Blade tags. It's a must to return view in you controller by rendering it, somewhere in the background Laravel procede all Blade Tag and return HTML that correspond to that tags.
What I can suggest you Is to create some route in your route file like this
Route::get('/about', function(Request $request){
// Automatically Laravel will look this file in the view directory
return view('about');
});
Or you can go with the controller like procedure by creating some controller, go in your terminal and execute
php artisan make:controller AboutController
this will generate a file name AboutController.php in app\Http\Controllers diretory within witch you will found
namespace App\Http\Controllers;
class HomeController extends Controller
{
}
after that add
public function index()
{
return View::make('about');
}
Don't forget to include use the Illuminale\Supports\Facades\View on top of your file
And one more important thing which left is to configure the Route, for that go in routes directory in the web.php file add
Route::get('/about', 'AboutController#index')->name('about');
I am using laravel 5.4 and trying to get index page, i am using following routes
Route::get('/',
['as' => 'home_page',
'uses' => 'Controller#index']);
and index function in controller looks like this:
public function index()
{
return view('index');
}
But when I visit mydomain.com, I get a different view than index.blade.php.
and it is fine when I use mydomain.com/? or on my local server.
I have searched everywhere in my code and in a google, but didn't found anything, any help?
ie: let me know if any further information required.
First make sure you are calling the right controller, and this dont have a specific middleware blocking the acess to your index method and index.blade.php is inside view folder.
If all of this is fine try this code on your rotes file:
Route::get('', function () {
return view('index');
})
Try this.
First use the make:controller Artisan command to create a controller file. let's say it is homeController.
php artisan make:controller homeController
Then in the homeController file write your code to get the view.
<?php
namespace App\Http\Controllers;
class homeController extends Controller
{
public function index()
{
return view('index');
}
}
Then define a route to this controller.
Route::get('/', 'homeController#index');
For more information please refer https://laravel.com/docs/5.5/controllers
There was a cached view saved on my server, I used
php artisan cache:clear and it got fixed. Thank you everyone for the support.
Its Laravel 5.
When the route.php contains this:
Route::get('/foo', function () {
return 'Hello World';
});
then the page shows with the text "Hello World".
However, as soon as I add this new line in route.php:
Route::get('/foo2', 'IndexController');
then the page show this error:
UnexpectedValueException in Route.php line 567: Invalid route action: [App\Http\Controllers\IndexController]
I previously created a controller with artisan which now looks like this:
class IndexController extends Controller
{
public function index()
{
echo 'test';
}
}
what am I doing wrong?
You have to specify wich method will be executed:
Route::get('/foo2', 'IndexController#index');
If you are using get method of Route. Normally first argument provided should be the url and second argument should be the method (there are other ways argument could be passed)
Route::get('/foo2', 'IndexController#index');
If you want to resourceful route . Normally first argument should be the resource name and the second argument should be RESTful controller name. (there are other ways argument could be passed).Example: photo is the resource name and PhotoController is the controller name.
Route::resource('photo', 'PhotoController');
in your case it should work this way
Route::resource('/foo2', 'IndexController');
or
Route::get('/foo2', 'IndexController#index');
so when you visit
yoursite.com/foo2
you will be displayed with IndexController index method
See reference more to learn laravel's restful resource controller
reference: https://laravel.com/docs/5.1/controllers#restful-resource-controllers
You need to specify the function inside the controller not just the controller:
Route::get('/foo2', 'IndexController#index');
You have to reference Controller#method as:
Route::get('/myroute', ['uses' => 'MyController#methodName']);