404 not found laravel - php

I am new to Laravel , I am getting 404 not found error when returning view to salary report from my controller. The below mentioned is my function which returns my simple view to salary report.
public function getSalaryReport()
{
return view('Company.salaryReport');
}
the routes.php file ahs route to company controller.
Route::group(['middleware' => 'auth.company'], function () {
Route::get('company/notice-board/create', 'CompanyController#getNoticeBoardCreate');
Route::get('company/notice-board/{id}/edit', 'CompanyController#getNoticeBoardEdit');
Route::get('company/designation/{id}/edit', 'CompanyController#getDesignationEdit');
Route::get('company/all-user/{id}/force', 'CompanyController#getForce');
Route::post('company/all-user/{id}/force', 'CompanyController#postForce');
Route::controller('company', 'CompanyController')
this is my view which i am trying to display from my controller.
#extends('Company.CompanyLayout')
#section('content')
<div>
<ul class="breadcrumb">
<li>
Home <span class="divider">/</span>
</li>
<li>
<a href='{!! URL::to("company/report-summery") !!}'>Summery Report</a>
</li>
</ul>
</div>
#endsection
where i am going wrong and what should be done to make my view visible. Thanks to all in advance.

Route::controller is depricated in the latest versions of Laravel, try not to use it anymore.
You can use Route::resource or create a specific route for your salary report like this:
Route::get('company/salary-report', 'CompanyController#getSalaryReport');
Also make sure that you have resources\views\Company\salaryReport.blade.php as your view.

404 not found is an error because you don't have any routes for the given url. And I didn't find any routes in your example for the function getSalaryReport()
if you want to call this method, at least add this to your routes:
Route::get('company/report-summery', 'CompanyController#getSalaryReport');

Related

Laravel 6.x Backpack NewsCrud Plugin

What I want to do is allow the admin panel to post news using newscrud. I am confused in how would I grab the information from the database and show the user the articles.
I am having trouble using the newscrud plugin for laravel. I quite don't understand how to use this plugin. I have installed it using composer. All the controllers, models etc. are in the vendor folder in my Laravel project.
Attempts:
What I tried to do is make a function in the
laravel-project/vendor/backpack/newscrud/src/app/Http/Controllers/Admin/ArticleCrudController.php file:
public function index()
{
# Pass the article database information in articles var
$articles = Articles::all();
# Return this variable to blog page
return view ('blog')->with('articles', $articles);
}
And in the routes/web.php file:
Route::get('/blog', 'ArticleCrudController#index')->name('blog');
Front-end code
#foreach($articles as $article)
<div class="col-md-12 d-flex ftco-animate">
<div class="blog-entry align-self-stretch d-md-flex">
<a href="blog-single.html" class="block-20" style="background-image: url('images/image_6.jpg');">
</a>
<div class="text d-block pl-md-4">
<div class="meta mb-3">
<div>July 20, 2019</div>
<div>Admin</div>
<div><span class="icon-chat"></span> 3</div>
</div>
<h3 class="heading">Even the all-powerful Pointing has no control about the blind texts</h3>
<p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
<p>Read more</p>
</div>
</div>
</div>
#endforeach
Error
The error message I get is:
Target class [App\Http\Controllers\ArticleCrudController] does not exist.
If you need information/screenshots I am willing to provide them.
When using composer in PHP, you should never make modifications to files inside the /vendor/ folder. Because as soon as you run composer update, they will get overwritten.
If I understand correctly, What you’re trying to do has little to do with Backpack. You should not overwrite the package in the vendor folder. You should create a controller in your app folder, with a routes in your routes folder, line you would normally do in Laravel. Just make sure that, when you reference the model, you reference Backpack\NewsCRUD\app\Models\Article instead of App\Models\Article.
Hope it helps!
The error message
App\Http\Controllers\ArticleCrudController
show that Laravel is not able to resolve the controller in the PHP namespace App\Http\Controllers.
I just looked into the library's code and I suggest you to replace
Route::get('/blog', 'ArticleCrudController#index')->name('blog');
by
Route::get('/blog', 'Backpack\\NewsCRUD\\app\\Http\\Controllers\\Admin\\ArticleCrudController#index')->name('blog');
Try to edit your web.php like this:
Route::group([
'prefix' => '/',
'middleware' => ['web'],
// This is all the namespace in directory
'namespace' => 'laravel-project\vendor\backpack\newscrud\src\app\Http\Controllers\Admin',
], function () {
Route::get('/blog', 'ArticleCrudController#index')->name('blog');
});
And edit your ArticleCrudController.php file to:
namespace laravel-project\vendor\backpack\newscrud\src\app\Http\Controllers\Admin;
Hope this can help :)

Laravel routing not working correctly for static page

/resources/views/layout/partials/nav.blade.php
<li>About</li>
/routes/web.php
Route::resource('tasks', 'TaskController');
/app\Http/Controllers/TaskController.php
public function about()
{
return view('tasks.about');
}
/resources/views/tasks/about.blade.php
#extends('layout.layout')
#section('content')
<div><h3>hello world </h3></div>
#endsection
Getting this error
Sorry, the page you are looking for could not be found.
change url to route and defined it into route file.
<li>About</li>
Route.php
Route::get('task/about', 'TaskController#about')->name('task.about');
If you want to use direct URL then you may use {{ url('task/about')}} instead of {{ route('task.about') }}
Note: Because as you defined resource in web.php file it contains many methods and URL.
Route::resource('tasks','eventcontroller');
Verb Path Action Route Name
GET /tasks index tasks.index
GET /tasks/create create tasks.create
POST /tasks store tasks.store
GET /tasks/{tasks} show tasks.show
GET /tasks/{tasks}/edit edit tasks.edit
PUT|PATCH /tasks/{tasks} update tasks.update
DELETE /tasks/{tasks} destroy tasks.destroy

Laravel routes with multiple slugs won't work in React

I have an application with a Laravel back-end/React.js front-end. I am using react router so to make that work I have any path pointing to the Controller which loads the view with the components in them. However when I add nested routes in the react side i.e. "blog/:blogId", it seems that it completely skips the tag in which components are loaded into and shows me content from the Laravel view instead.
I originally had:
`Route::get('/{slug?}', 'ProjectsController#index'`
I've tried:
`Route::any('{path}', function($path){
$projects = Project::all();
$posts = Post::all();
return view('welcome', compact('projects', 'posts'));
})->where('path', '.*');`
This won't work either:
`Route::get('/{slug?}/{id?}', 'ProjectsController#index'`
What I want is for both /blog and /blog/2 to go to ProjectsController#index which loads the view with the react tag.
The data in my index function in ProjectsController is:
`$projects = Project::all();
$posts = Post::all();
//return $projects;
return view('welcome', compact('projects', 'posts'));`
Has anyone come across this before? Thanks.
UPDATED:
The welcome view being returned by the controller index method:
The <div id="content"></div> is where my base component is being loaded into. So when navigating to route '/blog' I see my component, when navigating to '/blog/anything' I see Laravel's login and register links.
`#extends('layout')
#section('content')
#if (Route::has('login'))
<div class="top-right links">
#if (Auth::check())
Home
#else
Login
Register
#endif
</div>
#endif
<div id="content"></div>
#include('partials._scripts')
#endsection`
The component making use of the link:
`View here
<Route path="/blog/:blogId" component={Post} />`
My other routes in the base component:
`<Switch>
<Route exact path="/" render={(props)=> <Home text={text} mobileNavIsOpen={hamburgerOpen} backgroundImage={background}/>} />
<Route path="/projects" component={Projects} />
<Route path="/blog" component={Blog} />
<Route component={NotFound} />
</Switch>`
I've tried placing the /blog/:blogId route in the base app along with the others - still no difference.
UPDATE:
When removing the /blog/ route tag from react router and just keeping '/blog/:blogId, it has the same effect.
UPDATE/PARTLY SOLVED:
Adding (\\d+) to my react router path: path={/blog/:id(\\d+)} rightly took me to the nested component. It did also load the blade view content, however, so as a temporary fix I have taken out the blade content that was displayed. Would be good to see if anyone has another way around it. Thanks.
Try this
Route::get('/{any}', 'ProjectController#index')->where('any', '.*');
This is basically added to the end of the routes/web.php, since most probably you are trying to build a SPA and you want all http requests to be handled by react router.
Update:
Based on your updates I understand that you want both /blog and /blog/:ID to be handled by the same method. That can be done like this
Route::get('blog/{id?}', 'ProjectController#index')->where('id', '[0-9]+');
If you need the ID in the index method give it as the first argument to the method and send it to the view.

Laravel error: route not defined

Possible duplicate of this. But unable to get the answer in my case.
I need to use a link on my Laravel website, but it keeps resulting in "route not defined" error.
Html:
<ul class="nav navbar-nav">
#auth
<li>
Add post
</li>
#endauth
</ul>
web.php:
Route::get('/add-post', 'PagesController#add_post');
PagesController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PagesController extends Controller
{
public function add_post()
{
return view('add-post');
}
}
You need to name the route in order to do that:
For example:
Route::get('/add-post', 'PagesController#add_post')->name('add-post);
This is because when you use route('add-post') are are requesting a URL based on the name set in the web.php file
So you basically have two options here. When you use the route function, Laravel is looking for a named route. In order to name a route, you can add ->name('name-of-route-here') at the end of your route definition.
If you don't want to name your route, you can just use the url helper function instead of route, so your code would be url('add-post')
Documentation on named routes: https://laravel.com/docs/5.5/routing#named-routes
Documentation on url function: https://laravel.com/docs/5.5/helpers#method-url
Just change this:
<ul class="nav navbar-nav">
#auth
<li>
Add post
</li>
#endauth
web.php:
Route::get('add-post', 'PagesController#add_post');

Missing required parameters for [Route: homepage.edit] with link in layout

I'm new to Laravel 5.4 and php and I'm having some trouble to do my routing, so I wish you would explain to me what's going on !
I'm developing a back office for my future projects, and for my current project I need to be able to update data sent to the homepage. The edit of the page and the update of the data is now fully functional, I'm just having some trouble to do the link in the layout. Pretty sure it's a trivial problem, yet i'm having trouble figuring it out.
Here is my code :
web.php :
Route::group(['prefix' => 'admin', 'middleware' => 'admin'], function()
{
Route::resource('homepage', 'Admin\HomeController');
});
HomeController :`
public function edit($id) {
$contentExists = Homepage::first();
$homepage = Homepage::findOrFail($id);
return view('admin/homepage/edit', compact('homepage', 'contentExists'));
}`
In the layout :
<ul class="list-unstyled">
<li>
Page d'accueil
</li>
</ul>
Now for that I know I need to pass a parameter to the route, so I did like so :
<ul class="list-unstyled">
<li>
Page d'accueil
</li>
</ul>
But then it says the homepage variable is not defined, and I have no idea where I can define this variable since I'm in the layout, and also have no idea what needs to be inside this variable, what's his purpose... Can you help me with that ?
route second parameter, must be an array like this for example:
route('homepage.edit', ['id' => 2])

Categories