I'm new to Laravel and I also understand that Laravel has stopped supporting Collective but I managed to still install the package into my Laravel 5.8 project.
Now my problem is, when I tried adding the line below, it does not work. When I inspect element, it's not showing in the head section of the page.
{!! Html::style('css/parsley.css') !!}
Do you think it has something to do with the fact that Laravel no longer supports Collective or I'm doing something wrong here?
Thank you so much for your help guys!
I also tried using
<link href="{{ asset('css/parsley.css') }}" rel="stylesheet">
BUT STILL NOT WORKING.
This is the code of the whole page I'm working on.
#extends('main')
#section('title', '| New Post')
#section('stylesheets')
{{-- {!! Html::style('css/parsley.css') !!} --}}
<link href="{{ asset('css/parsley.css') }}" rel="stylesheet">
#endsection
#section('content')
<div class="jumbotron">
<div class="container">
<h1 class="display-4">Create New Post</h1>
<p class="lead"></p>
<hr class="my-4">
<p>Fill out the fields to write your post.</p>
{{-- <a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a> --}}
</div>
</div>
<div class="container">
<div class="col-sm-12 col-md-12">
{!! Form::open(array('route' => 'posts.store', 'data-parsly-validate' => '')) !!}
{{ Form::label('title', 'Title:') }}
{{ Form::text('title', null, array('class' => 'form-control', 'required' => '')) }}
{{ Form::label('body', 'Body:') }}
{{ Form::textarea('body', null, array('class' => 'form-control', 'required' => '')) }}
{{ Form::submit('Create Post', array('class' => 'btn btn-success btn-lg btn-block mt-2')) }}
{!! Form::close() !!}
</div>
</div>
#endsection
#section('scripts')
{!! Html::script('js/parsley.min.js') !!}
#endsection
I expected the parsley.css and parsley.min.js be imported into the page but it didn't work.
How does your template looks like? Do you have a #yield('stylesheets') in your template?
Where is your parsley.css located?
I fixed the problem. I had to remove the Collective codes and back to basic to make it work.
Related
I am using laravel collctive form. I want to update only the quantity field of the following form keeping the blood_id field readonly. When I submit the form I am not getting blood_id value.
How can i solve it?
{!! Form::model($bloodBank, ['route' => ['bloodBanks.update', $bloodBank->id], 'method' => 'put']) !!}
<div class="row">
<div class="col-lg-8">
<div class="form-group">
{!! Form::label('blood_id', 'Blood Group', ['class' => 'form-control-label']);!!}
{!! Form::select('blood_id', $bloods , null , ['placeholder' => 'Choose Blood Group',"class"=>"form-control",'disabled' => true]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="form-group">
{!! Form::label('quantity','Quantity', ['class' => 'form-control-label']);!!}
{!! Form::number("quantity",null, ["class"=>"form-control form-control-label",'min'=>'0']) !!}
<span class="validation-error">{{ $errors->first("quantity") }}</span>
</div>
</div><!-- col-12 -->
</div>
<button class="btn btn-info">Update </button>
{!! Form::close() !!}
For disabled fields, you may want to add hidden fields which won't display on the rendered page BUT will be included in the request object. E.g.
{{ Form::hidden('blood_id', $bloods) }}
This is in addition to the displayed field you already have which is disabled.
I want to edit a record in a CRUD application in laravel where I have a button which has been linked to go to the index view but when I click it, it redirects me to the UPDATE method of the controller.
This is my form:
{!! Form::open(['route' => ['players.update', $player->id], 'method' => 'PUT', 'files'=>'true']) !!}
<div class="row col-md-10 col-md-offset-1 panel">
<div class="col-md-8 col-md-offset-2">
<br />
<div class="form-group">
{{ Form::label('name', 'Player Name') }}
{{ Form::text('name', $player->name, ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('file', 'Upload Image') }}
{{ Form::file('pic') }}
</div>
<div class="form-group">
{{Form::button('Save Record', ['type' => 'submit', 'class' => 'btn btn-success'])}}
{!! Form::close() !!}
<a href="{{ route('players.index') }}">
<button class="btn btn-danger" >Cancel</button>
</a>
</div>
</div>
</div>
I have the following button for going back to the index page but this is taking me to the UPDATE method of the controller:
<a href="{{ route('players.index') }}">
<button class="btn btn-danger" >Cancel</button>
</a>
This is my index method in the controller:
public function index()
{
$players = Player::paginate(5);
return view('players.index', compact('players'));
}
This is the UPDATE method in the controller:
public function update(Request $request, $id)
{
return "Hi";
}
This is my route file contents:
Route::resource('news', 'NewsController');
Route::resource('competition', 'CompetitionsController');
Route::resource('players', 'PlayersConroller');
Everything looks fine to me but I don't know what goes wrong here.
Any help is appreciated in advance.
I am not sure if it will solve your issue, try to put your button code outside the form-group div.
You can change your code as
Cancel
You can check your html you have put button inside form tag which of type submit that's why it is submitting the form again.
Replace your form code with:
<div class="row col-md-10 col-md-offset-1 panel">
<div class="col-md-8 col-md-offset-2">
{!! Form::open(['route' => ['players.update', $player->id], 'method' => 'PUT', 'files'=>'true']) !!}
<br />
<div class="form-group">
{{ Form::label('name', 'Player Name') }} {{ Form::text('name', $player->name, ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('file', 'Upload Image') }} {{ Form::file('pic') }}
</div>
<div class="form-group">
{{Form::button('Save Record', ['type' => 'submit', 'class' => 'btn btn-success'])}}
</div>
{!! Form::close() !!}
</div>
<a href="{{ route('players.index') }}">
<button class="btn btn-danger">Cancel</button>
</a>
</div>
I'm new to Laravel and using ver 5.5. I have a simple view and when I run the code, instead of showing the rendered version, I see the Blade commands.
This is the view code:
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>{{ $title }}</h2>
</div>
<div class="pull-left">
{!! \App\Combine\BaseCombine::tableHeader($collection) !!}
{!! \App\Combine\BaseCombine::tableData($collection) !!}
{!! \App\Combine\BaseCombine::tableFooter($collection) !!}
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('transaction.index') }}"> Back</a>
</div>
</div>
</div>
#endsection
Here is the code in the controller that executes the view:
return view('general.genericTable',
[
'title' => __FUNCTION__,
'transactionID' => $transactionsID,
'type' => $type,
'collection' => TransactionCombine::agents($transactionsID, $type),
]
);
This is what I see when I execute the code:
#section('content')
{{ $title }}
{!! \App\Combine\BaseCombine::tableHeader($collection) !!} {!! \App\Combine\BaseCombine::tableData($collection) !!} {!! \App\Combine\BaseCombine::tableFooter($collection) !!}
Back
#endsection
What have I done wrong?
I am using voyager backoffice with laravel, and i'm having a problem with the blade coming from the database, all the code works except the blade, all the blade code outside the database works well.
I've already used {{ }}, {!! !!}, {{{ }}}, Html_entity_decode () but nothing works.
Any help is appreciated.
Thank you
View:
#extends ('layout')
#section ('content')
#foreach ($pageContent as $page)
{!! $page->slug !!}
{!! $page->title !!}
{!! $page->body !!}
#endforeach
#endsection
body that came from db:
<div class="container contacts_content_container">
<div class="row">
<div class="col-sm-12 text-center">
<div class="content">
<h1>Contact US Form</h1>
#if(Session::has('success'))
<div class="alert alert-success">
{{ Session::get('success') }}
</div>
#endif
{!! Form::open(['route'=>'contactus.store']) !!}
<div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
{!! Form::label('Name:') !!}
{!! Form::text('name', old('name'), ['class'=>'form-control', 'placeholder'=>'Enter Name']) !!}
<span class="text-danger">{{ $errors->first('name') }}</span>
</div>
<div class="form-group {{ $errors->has('email') ? 'has-error' : '' }}">
{!! Form::label('Email:') !!}
{!! Form::text('email', old('email'), ['class'=>'form-control', 'placeholder'=>'Enter Email']) !!}
<span class="text-danger">{{ $errors->first('email') }}</span>
</div>
<div class="form-group {{ $errors->has('message') ? 'has-error' : '' }}">
{!! Form::label('Message:') !!}
{!! Form::textarea('message', old('message'), ['class'=>'form-control', 'placeholder'=>'Enter Message']) !!}
<span class="text-danger">{{ $errors->first('message') }}</span>
</div>
<div class="form-group">
<button class="btn btn-success">Contact US!</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
Controller:
<?php
namespace App\Http\Controllers;
use App\Page;
use Illuminate\Routing\Controller;
class PageController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
// get all the pages
$pages = Page::all();
// load the view and pass the pages
return view('public.about')
->with('pages', $pages);
}
public function slug($slug)
{
// get page where slug
$pageContent = Page::where('slug', $slug)->get();
// load the view and pass the page content
return view('public.' . $slug)
->with('pageContent', $pageContent);
}
}
Routes:
//Pages Routing With slug
Route::get('/{slug}','PageController#slug');
I'd say keeping templates in a DB is not a good idea, but if you really need it you can parse Blade template manually. There are multiple ways to do that and one of these is using compileString() method:
$html = Blade::compileString($page->template);
May be compileString() might help you.Try this
Blade::compileString('Your blade syntax from db {!! $variable !!}');
I'm making a twitter look-a-like app.
I have a form to post a message on 1 blade (createMessage.blade.php) which is as followed:
#section('message')
{!! Form::open(['url' => 'message/postmessage']) !!}
<div class="form-group col-lg-6 col-lg-offset-3">
{!! Form::label('body') !!}
{!! Form::textarea('body', null,['class' => 'form-control']) !!}
</div>
<div class="form-group col-lg-6 col-lg-offset-3">
{!! Form::submit('Post message', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
#endsection`
Now I want to get my form on different pages (such as my timeline) but if I try #yield('message') it doesn't work.
timeline:
#extends('layouts.app')
#section('content')
#yield('message')
//some code for my timeline
#endsection
I can't find out why it doens't work.
Thanks in advance!
You have to use
#include('createMessage.blade.php') in the timeline file and remove the #section declaration in createMessage.blade.php