Why my form open not working in laravel 5.1? - laravel

Hi all I have problame with my form I am writing html form but its error
and this is my route code
Route::get('course','CourseController#index');
and this is my CourseController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class CourseController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('course.create');
}
and this is my view course/create.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="">
</head>
<body>
<div class="container">
{!! Form::open(array('route' => 'course.store')) !!}
<input type="text"><br>
<input type="password"><br>
{!! Form::close() !!}
</div>
</body>
</html>
and error:
Whoops, looks like something went wrong.
1/1 FatalErrorException in 818f720d4e075893d8198d2b0ff02e25 line 9: Class 'Form' not found
Help me please

With Laravel 5.* the Form & Html have been deprecated. Check out uprade guide (search Form & HTML Helpers).
1. Install laravelcollective/html
composer require laravelcollective/html
2. Add the Form and HTML facades and service provider.
Edit config/app.php and add this line to the 'providers' array:
'Collective\Html\HtmlServiceProvider',
Next, add these lines to the 'aliases' array:
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',

Related

Laravel Blade #yield is not working inside included view

I am trying to make layout using blade but the problem is that when i tried to
#yield on the file which is included in master file but #yield is not working.
resouces/views/layouts/app.blade.php
<html>
<head>
...
...
</head>
<body>
#include('layouts.navigation')
#include('layouts.main_panel')
#include('layouts.footer')
</body>
</html>
resouces/views/layouts/main_panel.blade.php
// some html stuff
#yield('form')
// some html stuff
resouces/views/auth/login.blade.php
#extends('layouts.app')
#section('form')
<form>
// input
</form>
#endsection
I would suggest you pass variables to the partials and echo
them inside it. This is an alternative way to achieve what you are
trying to do.
For example -
Partial blade file (resouces/views/partials.header.blade.php) -
<h4>{{ $name }}</h4>
View (resouces/views/custom.blade.php) -
#include('partials.header', [ 'name' => 'Lorem Ipsum' ])
I am also using laravel framework but i used to do in that way :-
Layout :- resouces/views/layouts/app.blade.php
<html>
<head>
...
...
</head>
<body>
#include('layouts.navigation')
#yield('content') // use #yield here why you need separate file
#include('layouts.footer')
</body>
</html>
After that :- resouces/views/auth/login.blade.php
#extends('layouts.app')
#section('content')
<form>
// input
</form>
#stop
Hope it helps!.. I used to follow this structure in laravel project

#yield('content') on laravel not working just plain white text

I've already installed Laravel Blade Highlighter..
#yield #section #endsection is not working, just a plain white text..
My views are working properly.. I can browser them okay..
Here's my code:
web.php:
Route::get('/', 'PagesController#index');
Route::get('/about', 'PagesController#about');
Route::get('/services', 'PagesController#services');
pagesController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PagesController extends Controller
{
public function index(){
return view('pages.index');;
}
public function about(){
return view('pages.about');
}
public function services(){
return view('pages.services');
}
}
app.blade.php
<h1>This is the laravel</h1>
#yield('content')
index.php:
#extends('layouts.app')
#section('content')
<h1>Welcome to Laravel</h1>
<p>this is a content</p>
#endsection
The answer is I should close all open tab on my sublime text..
And index.php, about.php and services.php should be index.blade.php, about.blade.php and services.blade.php

Getting error on laravel AppServiceProvider

I'm learning laravel 5.2 and trying to make a cms project by following a video tutorial. I have created the files as follows-
app/View/Composers/InjectPages.php
namespace App\View\Composers;
use App\Page;
use Illuminate\View\View;
class InjectPages
{
protected $pages;
public function __construct(Page $pages)
{
$this->pages = $pages;
}
public function compose(View $view)
{
$pages = $this->pages->all()->toHierarchy();
$view->with('pages', $pages);
}
}
app/Providers/AppServiceProvider.php
public function boot()
{
$this->app['view']->composer('layouts.frontend', Composers\InjectPages::class);
}
resources/views/welcome.blade.php
#extends('layouts.frontend')
#section('title', 'Welcome')
#section('heading', 'This is a heading')
#section('content')
<h1>Hello World</h1>
#endsection
public/themes/views/layouts/frontend.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>#yield('title') — Tuts24.com</title>
<link rel="stylesheet" type="text/css" href="{{ theme('css/frontend.css') }}">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">
<img src="{{ theme('images/logo.png') }}" alt="Tuts24.com">
</a>
</div>
<ul class="nav navbar-nav">
#include('partials.navigation')
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-12">
#yield('content')
</div>
</div>
</div>
</body>
</html>
public/themes/views/partials/navigation.blade.php
#foreach($pages as $page)
<li class="{{ Request::is($page->uri_wildcard) ? 'active' : '' }} {{ count($page->children) ? ($page->isChild() ? 'dropdown-submenu' : 'dropdown') : '' }}">
<a href="{{ url($page->uri) }}">
{{ $page->title }}
#if(count($page->children))
<span class="caret {{ $page->child() ? 'right' : '' }}"></span>
#endif
</a>
#if(count($page->children))
<ul class="dropdown-menu">
#include('partials.navigation', ['pages' => $page->children])
</ul>
#endif
</li>
#endforeach
But always getting the following error.
ErrorException in Container.php line 734:
Class App\Providers\Composers\InjectPages does not exist (View: /path/to/project/resources/views/welcome.blade.php)
I'm not sure, is these informations are sufficient to find out the error for you. If needed more information please let me know.
Looking forward to your response. Thanks.
Updates-
After several tries as answer it seems to me the following file is also related to this error. That's why I'm adding this code also and sharing a dropbox link of my learning project.
app/View/ThemeViewFinder.php
<?php
namespace App\View;
use Illuminate\View\FileViewFinder;
class ThemeViewFinder extends FileViewFinder
{
protected $activeTheme;
protected $basePath;
public function setBasePath($path)
{
$this->basePath = $path;
}
public function setActiveTheme($theme)
{
$this->activeTheme = $theme;
array_unshift($this->paths, $this->basePath.'/'.$theme.'/views');
}
}
Dropbox link
https://www.dropbox.com/sh/v8n1qvix20hywmo/AABVcs8DqvEhI89lw98mbxbya?dl=0
Try this:
composer('layouts.frontend', '\App\View\Composers\InjectPages::class');
Also, try to run composer dumpauto command.
Check it out
composer('layouts.frontend', '\App\View\Composers\InjectPages');
or
composer('layouts.frontend', \App\View\Composers\InjectPages::class);
Try by adding below code into composer.json
composer.json
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
"files":[
"app/View/Composers/InjectPages.php"
]
},
Do : composer dump-autoload
in : app/Providers/AppServiceProvider.php
public function boot()
{
view()->composer(
'layouts.frontend', 'App\View\Composers\InjectPages'
);
}

Retrieving data from database using laravel

I would like someone to help me step by step laravel process in retrieving data from a database. This is what I have done. The problem is no data is being displayed. I am not so good in this and need some help. Thanks
ViewController.php
<?php
namespace App\Http\Controllers\AddressBook;
use DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
class ViewController extends Controller
{
/**
* Show a list of all of the application's users.
*
*
*/
Public function getContacts(){
$contacts= AddressBookModel::all();
$data = ['contacts' => $contacts];
return view('view')->with($data);
}
}
Route
Route::get('contacts',[
'uses'=>'AddressBook\ViewController#getContacts'
]);
The Route is working well and its connecting and display the content in view.blade.php
view.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h2 align="center">These are the Registered Contacts in the Database</h2>
</body>
</html>
Try this :
Controller :
public function getContacts()
{
// Try to name your model Contact instead of AddressBookModel
$contacts= AddressBookModel::all();// = Contact::all();
return view('view')->withContacts($contacts);
}
View:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h2 align="center">These are the Registered Contacts in the Database</h2>
<table>
<!-- I assume that name and phone are contact model attributes-->
<th>Name</th>
<th>Phone</th>
#foreach ($contacts $as $contact)
<tr>
<td> {{$contact->name}} </td>
<td> {{$contact->phone}} </td>
</tr>
#endforeach
</table>
</body>
I added this function in the view.blade.php
#foreach($contacts as $display) {{$display}}
#endforeach

Trouble with blade templating in laravel 5

I'm trying to understand laravel's basic blade template engine, but I can't seem to get past a basic example. My blade template is not loading .It only show the white screen but when I remove the hello.blade.php to hello.php it works .Any suggestion?
Routes.php
Route::get('/', 'PagesController#home');
PagesController.php
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PagesController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function home()
{
return Views('hello');
}
}
hello.blade.php
<html>
<head>
<title>Hello World</title>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Starting to learn Laravel 5</div>
</div>
</div>
</body>
</html>
There is no Views helper. It's called view:
return view('hello');
Well, I had the same "white screen problem". And the blade docs in laravel is so confused. Then, try this:
Create a layout, lets say template.blade.php:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Starting to learn Laravel 5</div>
#yield('view_content')
</div>
</div>
</body>
Create a simple view that you want to wrap into the template, lets say hello.blade.php:
#extends('template')
#section('view_content')
This is my view content
#stop
Now, in your controller just call the view instead the layout:
public function home(){
return view('hello');
}
I'm not sure how it is working regardless of the extension as in your controller the syntax is incorrect. You return the view not Views... return view('hello'). You should technically see something like the following:
FatalErrorException in PagesController.php line 18:
Call to undefined function App\Http\Controllers\Views()
Even if app_debug is false you should see Whoops, looks like something went wrong.
I got this when I made a typo like so:
return views('abc');
instead of
return view('abc');
That extra s was killing everything.

Resources