Learning through some videos for Laravel but hit an issue i cant seem to figure out.
I have a route
Route::get('/post/{id}/{name}/{password}', 'PostController#showPost');
A custom controller called PostController.php
public function showPost($id, $name, $password) {
return view('post', compact('id','name','password'));
}
and the view called post.blade.php
<div class="container">
<h1>Post {{$id}} {{$name}} {{$password}}</h1>
</div>
when running the url
http://127.0.0.1/post/1/2/3
I get back a 404 page.
Looks like you need to allow .htaccess files. The problem is your routes aren't working.
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles
Related
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 having a problem using Laravel Framework. I am trying to build a layout, but no mater how much I've tried I am getting the same error on my browser :
View [layouts.adminLayout.admin_design] not found. (View:
E:\xampp\htdocs\laravel\ecom2\resources\views\admin\dashboard.blade.php)
m following this tutorial
https://www.youtube.com/watch?v=bzYBu0iez3s
here is code of admin_design.blade.php
#include('layouts.adminLayout.admin_header')
#include('layouts.adminLayout.admin_sidebar')
#yield('content')
#include('layouts.adminLayout.admin_footer')
and this is in dashboard.blade.php
#extends('layouts.adminLayout.admin_design')
#section('content')
this is the code of its controller
public function dashboard(){
return view('admin.dashboard');
}
if i write echo "test"; die;
then it shows die but is not showing the desired page... is there any solution for this prblm
Based on your usage this should be your structure:
resources
views
admin
dashboard.blade.php
layouts
adminLayout
admin_header.blade.php
admin_sidebar.blade.php
admin_footer.blade.php
admin_design.blade.php
if you have the layouts folder within your admin folder then you should use admin.layouts.adminLayout.VIEW_NAME
I'm trying to get a view where the user is able to create a topic. I did this many times in my project but never got this error, Because all of the other ones work just fine.
I get the error No query results for model [App\Topic] create. Here is the code.
This is the link that is supposed to bring the user to the view.
<div class="col s12">
<div class="card">
<div class="card-content clearfix">
New topic <i class="material-icons right">edit</i>
</div>
</div>
</div>
These are the routes that are used in this problem.
Route::get('/theme/{theme_id}/topics/create', 'TopicsController#create')->name('createtopic');
Route::post('/theme/{theme_id}/topics/create', 'TopicsController#store')->name('savetopic');
The Controller method create.
dd('Hij is er ' . $id);
And the store method is empty, The link doesn't show the DumpDie method but shows me the error instead. So there is no need to post the view i'm trying to display because that's not where the problem is. Thanks in advance!
You need to understand how routes and controller methods are working
Route::get('/theme/{theme_id}/topics/create', 'TopicsController#create')->name('createtopic');
When you are hitting the above route, i mean something for example yourdomain/theme/1/topics/create in your browser, then it will take 1 in place of theme_id and it will go to the create method of your TopicsController which will accept one argument.
Your create method should be something like that
public function create($id)
{
dd($id);
}
Here you will get 1 as result, because you have passed this argument in your url instead of theme_id.
I am setting up my own admin for a Laravel project and everything is going along fine until I hit what seems to be a routing issue. Here's my situation so far.
Within my views folder I have a folder named panel which holds all of my views for the admin panel. This is working perfectly. I have full access to the panel without a problem. Within the panel directory I have a folder named users which holds my views for the UsersControllers. This is where I'm struggling. My route for those views is as follows:
Route::resource('users', 'UsersController');
Route:list shows those routes as users.index, users.store etc.
In the top nav bar of the panel I have a link to the users index as
<li>Users</li>
I've also tried using
<li>Users</li>
Either way, this should be calling the index() method of the UsersController. That method looks like this
public function index()
{
return view('panel.users.index');
}
I've also tried just
public function index()
{
return view('users.index');
}
No matter what I try I get
NotFoundHttpException in RouteCollection.php line 161:
I would really appreciate a bit of wisdom on how to resolve this one.
you can use this for index
<li>Users</li>
or you can use action
<li>Users</li>
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.