Laravel Error 500 on a parametric route when in production - laravel

I built a small blog where a editor can create articles and post it and users can read it without login.
The issue that I'm having is the following :
In production server, if a user try to access a blog article from the home by clicking on the 'Read more' button, gets a 500 internal server error.
I'm also using other parametric routes and they are working perfectly fine.
In development server, everything works fine.
Any idea of what could the issue's cause?
Thanks in advance
In the home page I'm rendering a list of all the articles via the PublicController's index() method with the following code :
public function index()
{
$articles = Article::all();
return view('welcome', compact('articles'));
}
And it works perfectly fine.
But when a user click on a item of the list should be redirected, via the 'show()' method of the Public Controller, to the article's details page but in reality the user is getting a 500 internal server error.
The show() method :
public function show($id)
{
$article = Article::find($id);
return view('article', compact('article'));
}

One thing that can help you is to logging the exceptions in your Handler.php file. This way you can see the error details (message, file and code line).

Related

Test the view that is showing after authorisation

I am learning how to do simple tests on my application. Simply, I dont know how to get over the problem below.
Problem:
I am just trying to see, if my page is loading correctly by checking if site contain word "Send". Send is my button that is located in my view.
How can I check the view as a logged user?
My test function:
public function testSiteIsLoadingCorrectly()
{
$response = $this->get('/homepage');
$response->assertSee("Send");
}
After some research I got this function:
public function testSiteIsLoadingCorrectly() {
$user = User::factory()->create();
$response = $this->actingAs($user)
->withSession(['banned' => false])
->get('/');
$response->assertSee("Welcome on my page!");
}
It works great but only for "/". If I give another route, my console is showing a lot of text and finally it doesn't work.
How can I solve this?
assertSee() works bad with polish chars like ą,ę,ć etc...
That's the reason of all problems.
PS.
"Send" in Polish means "Wyślij"...

Laravel routes not working via GET while same route works via VIEW

I am trying to make a route that shows the user a secondary registration form, when i use this code:
Route::view('RegisterFamilyMembers', 'auth.registerFamilyMembers')->name('RegisterFamilyMembers');
The route works fine and routes to the file, but when i try to do the same via the GET method:
Route::get('RegisterFamilyMembers', 'Auth\FamilyMembersController#showRegistrationForm')->name('RegisterFamilyMembers');
And return the view in the controller:
public function showRegistrationForm()
{
return view('auth.registerFamilyMembers');
}
I get a RuntimeException page with no information on the problem.
does anyone know what can cause this problem?

Laravel redirecting to the previous page

I am inserting data to the database and redirecting back to the previous page using the code below in laravel
public function store(Request $request)
{
$todo=new Todo;
$todo->todo=$request->todo;
$todo->save();
return redirect()->back();
}
See My web page
After entering some data "new todo" it works well; data inserted and shows in the page but the page becomes like below.
I think the stylings are not working in the page
And after refreshing the page i got the page well.
What should be the problem?
You can try this
return back()->withInput();
You can save the previous URL in session so that you can easily redirect back to their previous URL,
Try this in your function,
public function store(Request $request)
{
$request->session()->put('url.intended',url()->previous());
$todo=new Todo;
$todo->todo=$request->todo;
$todo->save();
return redirect($request->session()->get('url.intended'));
}
Here, the Previous URL is generated by Helpers function of laravel.
Please comment if you have any doubts.

redirect is not working in codeigniter _construct function

I am facing a problem using redirect in _construct function,
In timesheet controller I wrote the following code and I am getting an error in the browser "
This problem can sometimes be caused by disabling or refusing to
accept
cookies.
Here is my code
class Timesheet extends MY_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('timesheet_model');
//$this->load->library('auth');
$username=$this->session->userdata('logged_in');
//$this->load->model('login_model');
if($username['fullname']!=""){
redirect('timesheet');
}
else{
redirect('login');
}
}
Please help me to find a way to get rid of this problem.
Thanks.
It looks to me like you're going around in a loop.
You check to see if the fullname element in your $username array is empty and, if it is, you redirect back to the same controller. I'm willing to bet it goes around in a circle like that for a while before the webserver throws up the error you mention.
If I'm reading what you're trying to do correctly, wouldn't you call another function within your Timesheet constructor if the fullname element is present to show whatever information it is that you're trying to display?
I'd suggest changing your logic to do the following:
if($username['fullname'] == ""){
redirect('login');
}
else{
//go to another controller method here
}
OK. I got it. The error is just because of I am redirecting to same controller where I have written the code. Everytime when it redirects to timesheet it enters into the construct function and it redirects again to timesheet. And the same thing is working like an endless loop.
So the fault was redirecting to the same controller.
I
use redirect like this : redirect('timesheet', 'refresh');

missing login page when redirect

i was create codeigniter controller like this :
function Home() {
parent::Controller();
if(!$this->session->userdata('id'))
redirect ('login');
$this->load->model('Home_Model');
}
but when i try to access the page, the redirect page now show. just show 404 not found but i was create login.php on controller and views also home_model.php on model.
what the problem with that code and how to fix that?
thank you
Because of this line: parent::Controller(), I assume that you are using CodeIgniter 1. Since you are building pages like home and login, I assume that you are starting building a new website. If my assumptions are right, I suggest you using the latest CodeIgniter (v2.1.0 at the moment, required PHP 5.1.6 or newer). You can grab a copy at CodeIgniter Home Page.
First of all, I think you should check your error reporting level. It should be something like error_reporting(E_ALL); for debugging. If not yet, turn it on and run the code again. Maybe you will get your own answer after that :)
After that, you should try the code below for your constructor to check that your home controller process as you expected.
function Home()
{
parent::Controller();
echo 'Home Class Initialized';
}
It should at least show 404 page. If it doesn't print out anything then we need more information. Maybe you should turn on logging and analyze your log files: look for /application/config/config.php: $config['log_threshold'] = 2;
If it print out 'Home Class Initialized' follow by a 404 message: please check if your controller have something like:
public function index()
{
echo 'Invoke default method';
}
If not yet, please add one. You may also want to take a look at using your own default method here
If it still a 404 then sorry, I have no idea. Maybe you should post more code.
If it print out 'Home Class Initialized' only: good. Now try this
function Home()
{
parent::Controller();
if ( ! $this->session->userdata('id'))
{
echo 'Redirecting to login page';
//redirect ('login');
}
$this->load->model('Home_Model');
}
If this print out Redirecting to login page, it's now time for you to uncomment //redirect ('login'); and check the login page. Follow the same path with step 1 & 2.
If not, check your session data: var_dump($this->session->userdata('id'). You could learn more about PHP falsehood here
After all, if it still fails, consider using __construct() of PHP 5
function __construct()
{
parent::__construct();
if ( ! $this->session->userdata('id'))
{
redirect ('login');
}
$this->load->model('Home_Model');
}
Other: if you use this $this->load->model('Home_Model');, I think you will have to call home_model like this $this->Home_Model->foo(); or there will be error access to NULL

Resources