Laravel white page loading route - laravel

I had a login.blade.php with some code, and I decided to replace with a new one.
I renamed it to old_login.blade.php and create a new file, in the same path, with the name login.blade.php.
After a while, I decided to rollback to my old login page.
I delete login.blade.php, and renamed the old_login.blad.php with the original name to return back.
No code was edited, only views.
The problem is that the page returned a blanck white page with many comments (the comment's tag is not closed).
I try to make a copy of the view, called test.blade.php, and change the route to that view. It diplay them correctly. But If I change another time route to myapp.login to display login.blade.php view, it won't work.
I try anything but nothing is changed. I'm using laravel 5.1.
The code insiede my routes.php is
Route::get('/', function () {
return view('myapp.login');
});
the code inside the login.blade.php (same ad test.blade.php) is:
#extends("app")
#section("content")
{!! Form::open(["url" => "home"]) !!}
<div class="form-group">
{!!Form::label("username", "Username:") !!}
{!!Form::text("usr_username", "Luca", ["class" => "form-control"]) !!}
</div>
<div class="form-group">
{!!Form::label("password", "Password:") !!}
{!!Form::input("password", "usr_password", "mypass", ["class" => "form-control"]) !!}
</div>
<div class="form-group">
{!!Form::submit("Login", ["class" => "btn-primary form-control"]) !!}
</div>
{!! Form::close() !!}
#include("errors.list")
#stop

So a nonsense answer to resolve my problem: I cutted the code inside login.blade.php, save file, pasted it, and saved another time. Now it display correctly.

Related

Laravel: REJECT ROUTE not defined but exists in web.php

I have a reject function in my Calendar controller but whenever I redirect to the view page it displays an error saying my route is not defined.
I've tried rearranging and renaming my route but it's still displaying the error.
Here is my form:
{!! Form::open(['url' => route('therapist.reject.appointment', $bookingRequest), 'method' => 'delete', 'onsubmit' => 'javascript:return confirm("Are you sure?")']) !!}
<button type="submit" class="btn btn-warning btn-block">Reject this appointment</button>
{{csrf_field()}}
{!! Form::close() !!}
Here are my routes. The other routes displayed are working perfectly:
Route::get('therapist-calendar/{bookingRequest}', 'TherapistCalander')->name('therapist.calendar');
Route::post('therapist-calendar/{bookingRequest}',
'TherapistCalander#saveAppointment')->name('therapist.book.appointment');
Route::patch('therapist-calendar/{bookingRequest}',
'TherapistCalander#finishedAppointment')->name('therapist.finish.appointment');
Route::delete('therapist-calendar/{bookingRequest}',
'TherapistCalander#rejectAppointment')->name('therapist.reject.appointment');
Route::delete('therapist-calendar/{bookingRequest}',
'TherapistCalander#cancelAppointment')->name('therapist.cancel.appointment');
And lastly, my function:
public function rejectAppointment(Request $request, BookingRequest $bookingRequest)
{
$bookingRequest->reject();
return redirect()->back()->with('rejectStatus', true);
}
The view page where this button belongs should be able to display the buttons for rejecting and finishing, alongside the calendar view.
EDIT
Follow up question: Is it possibly because the routes are similar to one another? If so, how do I fix this?
Try to change the Reject and Cancel the url string because it is similar.
Route::delete(
'therapist-calendar/{bookingRequest}/delete',
'TherapistCalander#rejectAppointment'
)->name('therapist.reject.appointment');
Route::delete(
'therapist-calendar/{bookingRequest}',
'TherapistCalander#cancelAppointment'
)->name('therapist.cancel.appointment');
Change your code to
{!! Form::open(['url' => route('therapist.reject.appointment', ['bookingRequest' => $bookingRequest]), 'method' => 'delete', 'onsubmit' => 'javascript:return confirm("Are you sure?")']) !!}
{{csrf_field()}}
<button type="submit" class="btn btn-warning btn-block">Reject this appointment</button>
{!! Form::close() !!}
The route parameters are passed as an array and that should work fine. Refer doc
Can you try this code
<form action="{{ route('therapist.reject.appointment', ['bookingRequest' => $bookingRequest]) }}" method="POST">
#method('DELETE')
#csrf
<button type="submit" class="btn btn-warning btn-block">Reject this appointment</button>
</form>
UPDATE
PROBLEM FIXED
I realized since they have similar links, web.php found it confusing so it did not read this route.
That is why I changed my route from:
Route::delete('therapist-calendar/{bookingRequest}',
'TherapistCalander#rejectAppointment')->name('therapist.reject.appointment');
To this:
Route::delete('doReject/{bookingRequest}',
'TherapistCalander#rejectAppointment')->name('therapist.reject.appointment');

Laravel: Pages not loading properly

This might look useless question, but I'm unable to understand the problem here.
The problems are:
1. When I load the page, first this loads:
And then, after uploading the file:
this page loads:
2. yield('content') is not working. Although #include is working fine.
3. I made master.blade.php, to load the first page of the website. Before it, I was working on the welcome page.But, then changed the work of welcome with the master blade, but when the page gets loaded, it doesn't show anything.
Routes:
Route::get('/',function() {
return view('welcome');
});
Route::group(['middleware' => ['web']], function(){
Route::get('upload',function(){
return view('pages.upload');
});
Route::post('/upload','UploadController#upload');
});
views/pages/upload:
#extends('welcome')
#section('content')
<h2>Upload Files Here</h2>
{!! Form::open(array('url' => '/upload','files'=>true))!!}
{!! Form::file('file') !!}
{!! Form::token() !!}
{!! Form::submit('Upload') !!}
{!! Form::close() !!}
#endsection
views/welcome:
<!DOCTYPE html>
<html lang="en">
<head>
#include('partials._head')
</head>
<body>
#include('partials._nav')
<div class="container">
#include('partials._messages')
#yield('content')
#include('partials._footer')
</div>
#include('partials._javascript')
UploadController/Controllers:
if($request->hasFile('file')){
$file = $request ->file('file');
$fileName = $file->getClientOriginalName();
$destinationPath = config('app.fileDesinationPath').'/'.$fileName;
$uploads = Storage::put($destinationPath,file_get_contents($file- >getRealPath()));
}
return redirect()->to('/upload');
When it's working fine when I used include, to include the upload page in welcome, but the result is like shown in the pictures.Also, When I tried to use the master blade, and exclude the use of the welcome page, by erasing the content of the welcome page, the blank page gets loaded.
What changes do I have to make to make use of master instead of the welcome page? Why are two pages getting loaded? also, why isn't yield('content') not working?
Also, the file which I'm uploading is not getting saved in the public/uploads folder.
Please can anyone help?

Laravel 5 Method not found exception

I use Laravel 5 and try to update a form:
{!! Form::model($user, ['route' => ['edit', $user->id], 'method' => 'PUT']) !!}
{!! Form::label('titel', 'First Name:'!!}
{!! Form::text('titel', null,) !!}
<button type="submit">Update</button>
{!! Form::close() !!}
My route:
Route::post('edit/{id}', ['as' => 'edit', 'uses' => 'UserController#editUser']);
My controller:
public function editUser($id){};
When click on the update Button I get MethodNotAllowedHttpException in RouteCollection.php
I checked in the browser source code and saw that Form::model(..) which I use generate the following output:
<form method="POST" action="http://localhost/myProject/public/edit/1" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="4nZlyfzzAZmTcZfThQ8gcR6cgEgYgR0ip0JZTKck">
Within the form there is the attribute method="POST" and the hidden input has the attribute value="PUT". This seems not correct for me. Any ideas? Thank you
You should use 'update' route to actually save the data (validate and persist it to the database). 'edit' route is what you used to generate edit form.
You should use PUT method to run method which saves data.
Also, here is small tip for you. Learn about how RESTful controllers work. They are really easy way to do what you're doing here (defenetly worth to learn them):
https://laravel.com/docs/5.1/controllers
Your route is not the same as your form.
Laravel uses the hidden inputs to specify the different http methods, as put.
So in your routes you should use a put method not a post.
Route::put();

Laravel use an icon to delete content

I have the following delete button:
{!! Form::open(['route' => ['tasks.destroy', $type->id], 'method' => 'delete']) !!}
{!! Form::submit('Erase this task?', ['class' => 'delete']) !!}
{!!Form::close() !!}
And now I would like to not use a button, but an icon to delete content. I would like to use this button: http://fortawesome.github.io/Font-Awesome/3.2.1/icon/remove-sign/
<i class="icon-remove-sign"></i> icon-remove-sign
The sign should be blue and small.
How do I do that? I only get error messages relating to models as a result. But when I dont make any changes it works perfectly.
Can someone give me an example of how to make the picture point to a delete route?
The form helper does not allow you to add HTML to it. Use a simple HTML button:
{!! Form::open(['route' => ['tasks.destroy', $type->id], 'method' => 'delete']) !!}
<button class="delete">
<i class="icon-remove-sign"></i> Erase this task
</button>
{!!Form::close() !!}

Laravel 5 stylesheets and scripts not loading for non-base routes

I am having trouble linking my stylesheets, scripts, and images for a non-base route in my Laravel 5 app. When I access example.com/about the scripts and stylesheets are working correctly but if I access example.com/about/something the scripts and stylesheets link to example.com/about/css/style.css rather than example.com/css/style.css
My code is as follows:
Routes.php:
Route::get('about/{slug?}', ['as' => 'officerProfile', 'uses' => 'PagesController#about']);
PagesController.php:
public function about($slug = 'president')
{
$officers = Officer::all();
$currentOfficer = Officer::where('slug', $slug)->first();
return view("pages.about", ['title' => $this->makeTitle('Learn About Us')])->with('officers', $officers)->with('currentOfficer', $currentOfficer);
}
layout.blade.php:
{!! HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!! HTML::script('js/skel.min.js') !!}
{!! HTML::script('js/skel-layers.min.js') !!}
{!! HTML::script('js/init.js') !!}
{!! HTML::script('js/scripts.js') !!}
<noscript>
{!! HTML::style('css/skel.css') !!}
{!! HTML::style('css/style.css') !!}
{!! HTML::style('css/style-desktop.css') !!}
</noscript>
For some reason Laravel is thinking the base URL is example.com/about when the loaded route is example.com/about/something. I have tried as well but it still routes to example.com/about/images/image.jpg rather than example.com/images/image.jpg. Any advice would be greatly appreciated. Thank you!
You are using relative paths and you need absolute paths. See the example below, the only thing I added is the prepended /
{!! HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!! HTML::script('/js/skel.min.js') !!}
{!! HTML::script('/js/skel-layers.min.js') !!}
{!! HTML::script('/js/init.js') !!}
{!! HTML::script('/js/scripts.js') !!}
<noscript>
{!! HTML::style('/css/skel.css') !!}
{!! HTML::style('/css/style.css') !!}
{!! HTML::style('/css/style-desktop.css') !!}
</noscript>
A relative path loads files related to the current path. Eg from the page http://example.com/about/us you can relatively load images/logo.png which results in the actual request to http://example.com/about/images/logo.png.
An absolute path is always from the hostname: same example as above but you'd load /images/logo.png which results in http://example.com/images/logo.png

Resources