Have a problem when used route to controller with variable - laravel-5

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.

Related

Laravel, Revolution Slider - Error when trying to embed

I am trying to add Revolution Slider to my Laravel instance (per instructions from its creators), and so far, I am getting the following error.
Facade\Ignition\Exceptions\ViewException Argument 2 passed to
Illuminate\Translation\Translator::get() must be of the type array,
string given, called in
/home/sasha/Documents/OffProjects/VetPartnersPrintPortal/project/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
on line 878 (View:
/home/sasha/Documents/OffProjects/VetPartnersPrintPortal/project/resources/views/home/index.blade.php)
The setup is quite simple (basic instructions).
class HomeController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('home/index');
}
}
View
<?php
include(app_path() . '/Slider/embed.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Example of Revslider embedding</title>
<?php RevSliderEmbedder::headIncludes(); ?>
</head>
<body>
<!-- change "example" in the code below to match your slider's alias -->
<?php
RevSliderEmbedder::putRevSlider('test');
?>
</body>
</html>
Does anyone have any idea what's going on here?
Revolution Slider is a Wordpress plugin, pretty sure it won't work with Laravel. If you click the revolution-slider tag on your question, you'll see that all other questions also have wordpress tag attached to them. I would recommend using sliders designed for Laravel, like this one or this one.
Pavel Lint was wrong. The wordpress and all yours plugin was developed in php, js and mysql. And the laravel is a framework for php...
Why the plugins wont work... I use the same revolution sliver in my projects and this work fine. Is this line of js script just include the "#" before param1, title and param2 like this #{{param1}} | .
This is solve the problem. Enjoy!

Laravel 5 requested url shows blank page with no error

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.

ESI tags in Laravel 5.3

For a Laravel 5.3 project I'm currently working on, the breadcrumb should be constructed dynamically based on a certain context. Since we need Varnish on this project I am trying to resort to the use of ESI tags.
I've set up a route that renders the breadcrumb and returns it as follows in routes/web.php:
Route::get('breadcrumbs', 'BreadcrumbController#showBreadcrumb');
This is what the controller looks like:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class BreadcrumbController extends Controller
{
public function showBreadcrumb(Request $request)
{
return 'Breadcrumb';
}
}
In my template I have the ESI tag defined as follows:
<esi:include src="{{ url('breadcrumbs') }}" />
Now, when I load the page I see the text "Redirecting to /breadcrumbs" at the place where the ESI tag should be rendered. Obviously I then get redirect to /breadcrumbs and see the output of my controller.
How can I stop this redirect behaviour and just have Laravel return the needed output?
Turns out, the localization middleware I was using on my web routes was causing the redirect. It redirected any route without a language prefix.
I'm using mcamara/laravel-localization. Removing the middleware from my breadcrumbs route fixed the problem.

Laravel 5.2 NotFoundHttpException in RouteCollection.php line 161 in single post view

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

How to echo browser locale in laravel 5.2

I want to echo the current set locale in my html tag using blade:
<html lang="{{ $locale }}"></html>
I'm new to Laravel 5 and i was wondering how to accomplish this.
If you are asking for locale set in client's browser, you can use request()->server('HTTP_ACCEPT_LANGUAGE') to get those.
And if you are asking for locale set within your Laravel application, you can get it like this: config()->get('locale')
And if you want to get template name in your Laravel blade, just use like this:
// allow $view_name in views
View::composer('*', function ($view) {
View::share('view_name', $view->getName());
});
On top of what #jszobody just said above, you could also make use of javascript and the jstz package in order to find their locale. Assuming you have jQuery installed, your code could look like the following
<script>
$(function() {
$('html').attr('lang', jstz.determine().locale());
}
</script>

Resources