Laravel 5.4 controller doesn`t show page - php

I have folder "aboutus" which contains 'index.blade.php' file and folder "thanks".
Folder "thanks"contains also 'index.blade.php'
My route for both of them:
Route::resource('admin/aboutus', 'AdminAboutusController',['names'=>[
'index'=>'admin.aboutus.index',
'create'=>'admin.aboutus.create',
'store'=>'admin.aboutus.store',
'edit'=>'admin.aboutus.edit'
]]);
Route::resource('admin/aboutus/thanks', 'AboutThanksController',['names'=>[
'index'=>'admin.aboutus.thanks.index',
'create'=>'admin.aboutus.thanks.create',
'store'=>'admin.aboutus.thanks.store',
'edit'=>'admin.aboutus.thanks.edit'
]]);
I have created controller for aboutus and thanks separately (AdminAboutusController and AboutThanksController)
AdminAboutusController index funnction returns view which i am able to see
public function index() { return view('admin.aboutus.index'); }
But controller AboutThanksController doesn`t shows me my page, it shows me white blank
public function index() { return view('admin.aboutus.thanks.index'); }
on php artisan route:list i can see that route is aviable.
Why it happens and how can I fix it?

Put thanks route above about us route
Route::resource('admin/aboutus/thanks', 'AboutThanksController',['names'=>[
'index'=>'admin.aboutus.thanks.index',
'create'=>'admin.aboutus.thanks.create',
'store'=>'admin.aboutus.thanks.store',
'edit'=>'admin.aboutus.thanks.edit'
]]);
Route::resource('admin/aboutus', 'AdminAboutusController',['names'=>[
'index'=>'admin.aboutus.index',
'create'=>'admin.aboutus.create',
'store'=>'admin.aboutus.store',
'edit'=>'admin.aboutus.edit'
]]);

Posting as an answer to close the question:
You have admin.aboutus.thnx.index but your folder is admin/aboutus/thanks/index
Please change to admin.aboutus.thanks.index and it should work

using route:list you are able to see list of routes but return view() function don't take route as a parameter. You have to give the file name and path.For example you want to show thanks.blade.php file which is inside admin/aboutus of your view folder. So you have to write:
return view('admin.aboutus.thanks');

Related

Route in Laravel doesnt work on get Methode

I have tried to create a route with GET methode and doesnt work !!!
the route i would like to see on browser bar
http://*******:8000/products/categories/index
My controller
public function index(Request $request)
{
$categories = Category::where('parent_id', null)->orderby('name', 'asc')->get();
return view('products.categories.allcategories', compact('categories'));
}
My View folder for catategories under products
views
products
categories
My Route file
Route::get('products/categories', [CategoryController::class, 'index'])->name('index');
when type php artisan route:list i have my route listed but when i try to get the category page it show 404 not found :
http://********:8000/products/categories
if i change the route to this and controller index function to list then it works
Route::get('products/categories/list', [CategoryController::class, 'index'])->name('index');
any idea where i made error !
Your products/{product} route is conflicting with the products/categories one; it's trying to find a product matching categories.
This can typically be resolved by reordering the two routes in the routes file, or adding a ->where('^[0-9]+$') constraint to the products/{product} route if {product} is supposed to be numeric.
you should try php artisan route:cache
i use that code after add new route always and it's work
You're going to the wrong url you need to go to
localhost:8000/products/categories
The index method does not relate to the URL but the action.

LARAVEL Returning Blank View With No Error

When I click the link leading to /[page]/ffacts, where [page] is one of zagor, dylan_dog or superman, I get a blank page.
The view is in resource/views/[page]/ffacts.blade.php
These are the routes:
Route::get('/', 'PagesController#home');
Route::resource('zagor', 'ZagorController');
Route::resource('dylan_dog', 'DylanDogController');
Route::resource('superman', 'SupermanController');
Route::get('/zagor/ffacts', 'ZagorController#ffacts');
Route::get('/dylan_dog/ffacts', 'DylanDogController#ffacts');
Route::get('/superman/ffacts', 'SupermanController#ffacts');
Code in Controllers:
public function ffacts()
{
return view('Superman.ffacts', compact('superman'));
}
Change it like this:
Route::get('/', 'PagesController#home');
Route::get('/zagor/ffacts', 'ZagorController#ffacts');
Route::resource('zagor', 'ZagorController');
Route::get('/dylan_dog/ffacts', 'DylanDogController#ffacts');
Route::resource('dylan_dog', 'DylanDogController');
Route::get('/superman/ffacts', 'SupermanController#ffacts');
Route::resource('superman', 'SupermanController');
Problem is, that /zagor/ffacts get matched by Route::resource('zagor', 'ZagorController'); because resource generate all routes for all CRUD operations, so also something like this /zagor/{id}
And this is matched before your custom. You can also check this by running artisan command: php artisan route:list
From what I can see, if your directory structure is really
resource/views/page/ffacts.blade.php
then you will need to be using the following return command for the view
public function ffacts()
{
return view('page.ffacts', compact('superman'));
}
To use return view('Superman.ffacts') you would need a directory structure of resources/views/Superman/ffacts.blade.php

laravel making its own route to blade file

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 can't see the view using Laravel

I have a problem with seeing a view.
Well, I went to url that will take me to the view and I added the link
<a href="{{URL::to('/view_product/'.$v_published_product->product_id)}}">
<p>{{$v_published_product ->product_name}}</p>
</a>
then I went to the routing file and I added the route :
Route::get('/view_product/{product_id}', 'HomeController#product_details_by_id');
I went to the controller and I wrote the product_details_by_id method :
public function product_details_by_id($product_id) {
$product_by_details=DB::table('tbl_products')
->join('tbl_category','tbl_products.category_id','=','tbl_category.category_name')
->join('tbl_manufacture','tbl_products.manufacture_id','=','tbl_manufacture.manufacture_name')
->select('tbl_products.*','tbl_category.category_name','tbl_manufacture.manufacture_name')
->where('tbl_products.product_id',$product_id)
->where('tbl_products.publication_status',1)
->limit(18)
->first();
$manage_product_by_details=view('pages.product_details')
->with('product_by_details',$product_by_details);
return view('layout')
->with('pages.product_details',$manage_product_by_details);
When I go the link /view-product/32 as an example: I found just the layout without the page pages.product_details.
Ps : I did not forget to put #extends('layout') #section('content') and #endsection.
edit 1 :
i tried to make the method simple:
public function product_details_by_id($product_id) {view('pages.test')}
test is a view i created in pages folder with "hello!!". Normally i have to see a white page with Hello!! but all I see is a white page.
Thank you in advance!
Try this code in the controller:
public function product_details_by_id($product_id) {
$product_by_details=DB::table('tbl_products')
->join('tbl_category','tbl_products.category_id','=','tbl_category.category_name')
->join('tbl_manufacture','tbl_products.manufacture_id','=','tbl_manufacture.manufacture_name')
->select('tbl_products.*','tbl_category.category_name','tbl_manufacture.manufacture_name')
->where('tbl_products.product_id',$product_id)
->where('tbl_products.publication_status',1)
->limit(18)
->get();
return view('pages.product_details')
->with('product_by_details',$product_by_details);
}
make sure that the pages folder is inside resources/views
and return view('pages.test');

I am unable to access Laravel view

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');

Categories