I want to show a page when a url is requested but what i get is a blank page despite the fact that the page has content in it. I've been trying to figure what could be wrong with my code but have come up with nothing so far. Here's what i have in my code
In my web.php file, i have this route
Route::get('/home', 'HomeController#index')->name('home');
// Student
Route::get('/students', 'StudController#index');
Route::get('/student/create', 'StudController#create');
Route::post('/students', 'StudController#store');
// Employee
Route::get('/employees', 'EmpController#index');
Route::get('/employee/create', 'EmpController#create');
Route::post('/employees', 'EmpController#store' );
Route::get('/employee/{id}', 'EmpController#show');
// Faculty
Route::get('/faculty', 'FacultyController#index');
In the EmpController file, this is the method to show the employee with the id (note the absence of a query as I'm only testing to see if a page is displayed when this uri is requested)
public function show()
{
return view('emp.employee');
}
This is the link
<i class="fa fa-file-text-o" aria-hidden="true"></i>
This is my employee.blade.php inside the resources/views/emp/ folder
#extends('layouts.master')
#section('content')
<h3>Why is this page blank?</h3>
#endsection
Error reporting is set to true. What have i missed? This should be simple
After rebooting my system, i was still not able to access the link correctly. Checked laravel.log file and nothing pointed to the issue in it. However i was able to fix this by creating another controller and everything worked perfectly. Still don't know why i had issues though.
Related
I have a html form inside one of my views that is supposed to get an image the user uploads and save it, the form is below:
<form class="col-lg-12" action="/banner/store/">
The form itself is quite large, but later on there's a to end it. It was supposed to redirect me to the banner/store where my Banner controller have a dd() function so I can confirm everything is okay. But instead, I get a blank white screen and the url goes banner/store/?.
The routes to the BannerController seems to be correct since banner/create works, the problem is when I go from create to store, but anyways, here's how I set the Routes:
Route::resource('banner', 'BannerController');
Any ideas why my banner/store won't work? And why is there a question mark on the end of the url? Sorry if this may be a dumb error, I'm still learning coding.
Your action is is wrong. When you use the resource static method then the store-url is the same as the GET url.
You can achive your goal with:
<form class="col-lg-12" action="{{ route('banner.store') }}" method="POST">
See more information in documentation.
When you updating your banner, you can't use the browser native form with PUT.
See in this document how laravel will handle that for you.
I'm trying to redirect to another page with the click of a button, but for some reason it's not working, I'm not sure why?
Currently it opens up a window inside the main page not even a real redirect but it's blank. If I change the link to something else like just "/" or another page like "/users" then it works, but just for this link it's not working.
This is how I'm redirecting in the vue
<inertia-link href="imports/teachers">
<el-button type="warning">Import</el-button>
</inertia-link>
In my web.php
Route::resource('imports/teachers', 'ImportTeacherController');
In the controller
public function index()
{
return Inertia::render('Import/Teacher');
}
In the teacher.vue I have a very basic layout
<template>
<layout>
<div>
<h1>Page Title</h1>
</div>
</layout>
</template>
<inertia-link href="imports/teachers"> -> <inertia-link href="/imports/teachers">
You are missing a / before imports. It's just the same with normal anchor tags, you should add a leading /.
You must make <inertia-link href="/imports/teachers">
There is also an even better solution which I always use. With this you can use routing names just have a look at it then it goes like this <inertia-link href="route('import.teachers')"> https://github.com/tighten/ziggy
Or you add it manually how it works you can find here: https://inertiajs.com/routing at Generating URLs.
I used Laravel route as follow.
Route::get('report/centos7/{id}', 'HomeController#centos7');
And then in Controller, I used this code to return View.
\View::make('report/centos7/', $id);
An error occurred as follow.
InvalidArgumentException in FileViewFinder.php line 137:
View [report.centos7.] not found.
I called the URL like this "mysite/laravelproject/public/report/centos7/result_target2"
I using Laravel 5.2
First time I used this code in Controller
return \View::make('report/centos7/'. $id);
But, the CSS and JS is not loaded. I think because of "."
That is why I changed from "." to ","
Route
Route::get('report/centos7/{id}', 'HomeController#centos7');
HomeController
public function centos7($id)
{
//
return \View::make('report/centos7', $id);
}
I had dynamically added "blade.php" into folder view/report/centos7/xxxx.blade.php
I created a new page to list all files in that folder and link each of the files to show the report in blade format.
I hope Laravel route to Controller is can help to access my report in blade format
Thanks for help. I'm a newbie in programming language
Update
I removed {id} in route as follow
Route::get('report/centos7/{id}', 'HomeController#centos7');
To
Route::get('report/centos7/', 'HomeController#centos7');
And removed id in HomeController as well
It works. But, I still want to send $id from Route to HomeController
When I do that I don't know why CSS is not loaded in my blade php.
Please help.
Update (Sovled)
Thank god everyone
If anyone has the same problem as me
I changed my href into the layout as follow and it works.
<link href="{{ URL::asset('theme/vendor/bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
The main issue is the extra / in your view code:
\View::make('report/centos7/', $id);
If you change it to the following, it should all work correctly:
\View::make('report.centos7', $id);
Make sure that your HTML code is in the resources/views/report/centos7.blade.php file.
I'm a beginner in Laravel and I need your help. I have successfully displayed the contents of my post controller on the index page, but I want to be able to click on each post and have it displayed on another page. I'm using Laravel 5.2.
Here's my controller:
`
public function show($id)
{
$post= Post::find($id);
return View::make('posts.viewpost')->with('post', $post);
}
`
Here is my Route:
Route::get('posts/viewpost/{id}','PostsController#show');
Here's my index page which currently displays all posts:
`
#foreach($posts as $post)
{{$post->title}}
{{$post->description}}
Read More
#endforeach
`
I want to be able to click on 'Read More' and have each post displayed on a new page viewpost.blade.php
After running the project and I try to click each post, I keep getting this error page:
shown in this image.
I really do not understand why this error appears each time I click on one of the posts, please guys help me. Thanks in anticipation for your help.
Try with url:: to may be its not taking your base path
Try with this code
<a href="{{ URL::to('posts/viewpost/'.$post->id) }}">
Thanks guys, I've been able to figure it out.
I had to update this line:
Read More
to this:
Read More
Simplified my main.blade.php template looks like this...
<html>
<head>
#inlcude("header")
#yield("addToHeader")
</head>
<body>
#yield("content")
#include("footer")
</body>
</html>
Let's say my controller points to login.blade.php and it provides addToHeader and content sections. When my footer is included, I'd like to append the addToHeader section but I just can't get it to work.
In my footer I have tried
#section("addToHeader")
#parent
This is the added content
#yield("addToHeader")
#stop
And variations of this.
Now, for the sake of doing it right and in hopes that I might not spend my resources on doing this the incorrect or inefficient way, here is what I am trying to accomplish by doing this...
When a user logs in every time they try to load a new page, I want the website to throw a message to the user (in my case I am actually "locking" the page down with a modal) that lets the user know he/she must finish setting up her profile before anything else can be done. Is there a controller or route that doesn't care which page/action is being requested and allows me to send extra data to the template - even if it is just $data["lockdown"]=true?
I don't know if it's the best way to do it but i would go for something like this.
Using a session variable to know if the user has to set-up his profile or not:
Session::put('profile_uncompleted',true);
You can set this variable when the user log-in for exemple.
Then on your main.blade.php you can check if you have to display your modal:
#if(Session::has('profile_uncompleted')
#include('modal')
#endif
Where modal contains your Html modal content.