Laravel blade views not showing updated content - php

I have a Laravel site running on a GoDaddy share hosting plan. I'm on PHP version 7.1. It has functioned fine up until yesterday. Now the blade views no longer show changes that occur on the database.
I see that the POST functions are working, as the changes are reflected in the database. They're just not showing up in the views themselves.
I've tried to clear the view cache as suggested here: Blade view not reflecting changes
I have also changed the timezone in config/app to 'America/Phoenix' to try and match godaddy's servers: https://www.godaddy.com/community/cPanel-Hosting/How-To-Change-Timezone-on-a-shared-server/td-p/102712
I've contacted GoDaddy's tech support and they couldn't find anything they believed could cause it.
Example Route:
//Resource
Route::resource('beer', 'BeerController');
Example Controller:
public function update(Request $request, Beer $beer)
{
$this->validate($request, ['name' => 'required']);
$beer->update(request(['name', 'beer_style_id', 'style', 'abv', 'ibus', 'srm', 'brewery_id', 'on_tap']));
return view('beers.show', compact('beer'));
}
Example View
#extends('layouts.master')
#section('content')
<div class="row">
<div class="col-sm-12">
<h1>Edit {{ $beer->name }}</h1>
<hr />
{!! Form::model($beer, ['route' => ['beer.update', $beer->id], 'method' => 'patch']) !!}
<div class="form-group">
{!! Form::label('name', 'Name') !!}
{!! Form::text('name', $value = null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('brewery_id', 'Brewery') !!}<br />
{!! Form::select('brewery_id', $breweries, null, ['placeholder' => 'Select Brewery', 'class' => 'custom-select mb-2', 'style' => 'width:100%;']) !!}
</div>
<div class="row" style="margin-bottom: 1rem;">
<div class="col">
{!! Form::label('beer_style_id', 'Style Family') !!}<br />
{!! Form::select('beer_style_id', $beerstyles, null, ['placeholder' => 'Select Style', 'class' => 'custom-select mb-2', 'style' => 'width:100%;']) !!}
</div>
<div class="col">
{!! Form::label('style', 'Style') !!}
{!! Form::text('style', $value = null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="row" style="margin-bottom: 1.5rem;">
<div class="col">
{!! Form::label('abv', 'ABV') !!}
<div class="input-group">
{!! Form::number('abv', $value = null, ['class' => 'form-control', 'step' => '.1']) !!}
<span class="input-group-addon">%</span>
</div>
</div>
<div class="col">
{!! Form::label('ibus', 'IBUs') !!}
{!! Form::number('ibus', $value = null, ['class' => 'form-control']) !!}
</div>
<div class="col">
{!! Form::label('srm', 'SRM') !!}
{!! Form::number('srm', $value = null, ['class' => 'form-control', 'step' => '.1']) !!}
</div>
</div>
<div class="form-group" id="on-tap-checkbox">
{!! Form::checkbox('on_tap', '1') !!} On Tap
</div>
<div class="form-group">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
Cancel
</div>
#include('layouts.errors')
{!! Form::close() !!}
</div>
</div>
#endsection

Related

Laravel 5 storing empty row in database?

I'm currently working on a simple blog system for my website, I'm using Laravel 5.5 for this, but I'm having a problem. Whenever I create a new article using the form I created, it is storing a empty row in my database instead of the data from the form...
This is my function to store a article:
public function newsStore()
{
$input = Request::all();
Article::create($input);
return $input;
}
According to the tutorial that I'm following should this do the trick.. This is the form that I'm currently using:
{!! Form::open(['url' => 'news']) !!}
<!-- Article Title -->
<div class="form-group row">
{!! Form::label('title', 'Title:', ['class' => 'col-2 col-form-label']) !!}
<div class="col-10">
{!! Form::text('title', null, ['class' => 'form-control']) !!}
</div>
</div>
<!-- Article Description -->
<div class="form-group row">
{!! Form::label('description', 'Description:', ['class' => 'col-2 col-form-label']) !!}
<div class="col-10">
{!! Form::text('description', null, ['class' => 'form-control']) !!}
</div>
</div>
<!-- Article Excerpt -->
<div class="form-group row">
{!! Form::label('excerpt', 'Excerpt:', ['class' => 'col-2 col-form-label']) !!}
<div class="col-10">
{!! Form::text('excerpt', null, ['class' => 'form-control']) !!}
</div>
</div>
<!-- Article Image -->
<div class="form-group row">
{!! Form::label('image', 'Image:', ['class' => 'col-2 col-form-label']) !!}
<div class="col-10">
{!! Form::file('image') !!}
</div>
</div>
<!-- Article Message -->
<div class="form-group row">
{!! Form::label('message', 'Message:', ['class' => 'col-2 col-form-label']) !!}
<div class="col-10">
{!! Form::textarea('message', null, ['class' => 'form-control', 'rows' => '7']) !!}
</div>
</div>
<!-- Article Submit -->
<div class="form-group">
{!! Form::button('Add Article', ['class' => 'btn btn-primary waves-effect waves-light float-right', 'type' => 'submit']); !!}
</div>
{!! Form::close() !!}
This is the route I'm using:
Route::post('news', 'DashboardController#newsStore'); // The articles store route
This is my model:
class Article extends Model
{
protected $fillable = [
'title',
'description',
'excerpt',
'image',
'body',
'published_at'
];
}
I have done this once before and have tried to redo it all but can't seem to figure out what is going wrong.
Thanks in advance!
To make create() work make sure you're using columns with same names. For example, if your column name is title, you need to use title instead of news-title in the form too:
{!! Form::text('title', null, ['class' => 'form-control']) !!}
As you use this Article::create(); it means all your input names should be same as table column name.
Ex:
<input name="title" ... same be same to column call news-title in respective table
If not same
Use Query Builder
DB::table('table_name')->insert(
[
'name' => $input->news-title
.....
]
);
Read More about Hyphens in column names in MySQL DB

File Not Updating in Laravel

I have Laravel 5.5 Application. I am trying to update my post and image is not updating. When I die and dump the following
dd($request->hasFile('image'));
it outputs false
View:
<div class="box-body">
{{ Form::model($slider, array('route' => array('admin.slider.update', $slider->title), 'method' => 'PUT')) }}
<div class="form-group">
{!! Form::label('title', 'Title') !!}
{!! Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Title']) !!}
</div>
<div class="form-group">
{!! Form::label('content', 'Content') !!}
{!! Form::textarea('content', null, ['class' => 'form-control', 'placeholder' => 'Content']) !!}
</div>
<div class="row">
<div class="col-md-2 col-xs-6">
<div class="form-group">
{!! Form::label('image', 'Change Image') !!}
{!! Form::file('image') !!}
</div>
</div>
<div class="col-md-10 col-xs-6">
<img src="{{ secure_asset('images/slider/thumb/' . $slider->image )}}" class="img-responsive" width="150">
{{ $slider->image }}
</div>
</div>
{!! Form::submit('Submit', array( 'class'=>'btn btn-info' )) !!}
{!! Form::close() !!}
</div>
Controller:
public function sliderupdate($slider, Request $request){
$slider = Slider::where('title', $slider)->firstorfail();
$slider->title = $request->title;
$slider->content = $request->content;
dd($request->hasFile('image'));
if ($request->hasFile('image')) {
$file = Input::file('image');
//getting timestamp
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$name = $timestamp. '-' .$file->getClientOriginalName();
$file->move(public_path().'/images/slider/', $name);
$slider->image = $name;
$thumb = Image::make(public_path().'/images/slider/' . $name)->resize(1920,1080)->save(public_path().'/images/slider/thumb/' . $name, 90);
}
$slider->save();
return redirect()->route('admin.slider.edit', $slider->title)->with('status', 'Update Success');
}
Route:
Route::put('admin/slider/{slider}', [
'uses' => 'AdminController#sliderupdate',
'as' => 'admin.slider.update'
]);
Something I am missing, but couldn't find out what it is.
You are missing the 'files' => true option. You need files option in the array passed to Form::open or Form::model if you are going to accept files.
{{ Form::model($slider, [
'route' => ['admin.slider.update', $slider->title],
'method' => 'PUT',
'files' => true
]) }}
Method:
public function slideredit($slider){
$slider = Slider::where('title', $slider)->firstOrFail();
return view('admin.slider.edit', compact('slider'));
}
Change your Form to
{!! Form::model($slider, ['route' => ['admin.slider.post', $slider->title, 'method' => 'PUT', 'files'=>true]]) !!}
<div class="modal-body">
<!-- text input -->
<div class="form-group">
{!! Form::label('title', 'Title') !!}
{!! Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Title']) !!}
</div>
<div class="form-group">
{!! Form::label('content', 'Content') !!}
{!! Form::textarea('content', null, ['class' => 'form-control', 'placeholder' => 'Content']) !!}
</div>
<div class="form-group">
{!! Form::label('image', 'Choose Image') !!}
{!! Form::file('image') !!}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
{!! Form::submit('Submit', array( 'class'=>'btn btn-info')) !!}
</div>
{!! Form::close() !!}

Showing dropdown value in laravel form select List?

Here is my code:
controller file: EmergencyContactsController.php
$surnames = DB::table('salutations')->pluck('name');
return view('patient/emergencycontacts', ['salutation' => $surnames]);
Blade file: patient/emergencycontacts.blade.php
{!! Form::open(array('route' => 'emergencycontacts_store', 'class' => 'form')) !!}
<div class="form-group">
{!! Form::label('Salutation') !!}
{{ Form::select('role', ['' => 'Select Role'] + $salutation, null, ['class' => 'form-control']) }}
</div>
<div class="form-group">
{!! Form::label('First Name') !!}
{!! Form::text('firstname', null, array('required', 'class'=>'form-control', 'placeholder'=>'First Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Last Name') !!}
{!! Form::text('lastname', null, array('required', 'class'=>'form-control', 'placeholder'=>'Last Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Relationship') !!}
{{ Form::select('relationship', ['Father', 'Mother', 'Husband','Wife','Son','Daughter','Uncle','Aunty','Other']) }}
</div>
<div class="form-group">
{!! Form::label('Phone') !!}
{!! Form::text('phone', null, array('required', 'class'=>'form-control', 'placeholder'=>'Phone')) !!}
</div>
<div class="form-group">
{!! Form::label('Fax') !!}
{!! Form::text('fax', null, array('class'=>'form-control', 'placeholder'=>'Fax')) !!}
</div>
<div class="form-group">
{!! Form::submit('Save',array('class'=>'btn btn-primary')) !!}
</div>
{{ Form::close() }}
When I go to url http://localhost:8000/patient/emergency-contacts/create it gives me error:
"Unsupported operand types"
You need to change 2 things
In your controller:
$surnames = DB::table('salutations')->pluck('name', 'id')->toArray();
So you get an array as [id => 'value'] and not only ['value']. In the View:
{!! Form::select('role', $salutation, null, ['class' => 'form-control']) !!}
{!! Form::select('relationship', ['Father', 'Mother', 'Husband','Wife','Son','Daughter','Uncle','Aunty','Other']) !!}
{!! Form::close() !!}
Always 'escape' the Form tags, if not, the HTML will be printed on screen, not parsed.
please use view('patient.emergencycontacts', ['salutation' => $surnames]);

Laravel 5.1 PHPunit form testing fails every time

I have a test set up like this
use WithoutMiddleware;
public function test_it_submits_forms()
{
$this->visit('/admin/menu/samples')
->click('New Sample')
->seePageIs('/admin/menu/samples/new/create')
->type('test1', 'name')
->type('test2','description')
->type('test2','introduction')
->select(11, 'scenario_id')
->type('test','slug')
->press('Add');
}
and the file I am testing like this.
{!! Form::open(['url' => 'admin/menu/samples/', 'method' => 'POST']) !!}
<div class="row"><div class="form-group col-xs-8 col-md-7 {!! $errors->has('name') ? 'has-
error' : '' !!}">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null,['class' => 'form-control']) !!}
{!! $errors->first('name', '<span class="help-block">:message</span>')!!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('introduction', 'Introduction:') !!}
{!! Form::textarea('introduction',null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('description', 'Description:') !!}
{!! Form::textarea('description',null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7 {!! $errors->has('slug') ? 'has-error' : '' !!}">
{!! Form::label('slug', 'URL:') !!}
{!! Form::text('slug',null, ['class' => 'form-control']) !!}
{!! $errors->first('slug', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('available_from', 'Available from:') !!}
{!! Form::date('available_from', \Carbon\Carbon::now(), ['class' => 'form-control2']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('available_until', 'Available until:') !!}
{!! Form::date('available_until', \Carbon\Carbon::now(), ['class' => 'form-control2']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('needs_auth', 'Needs authentication:') !!}
{!! Form::checkbox('needs_auth', 'value', false) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::label('is_active', 'Active:') !!}
{!! Form::checkbox('is_active', 'value', false) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
<h3>Add a scenario</h3>
{!! Form::select('scenario_id',($scenario), null,
['id'=>'scenario_id','placeholder' => 'Select one...']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::submit('Add', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
The test throws undefined variable errors on both of the variables $errors in form elements name and slug ( they just light up the form if something is not filled properly).
Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/home/vagrant/C...', 9, Array)
Could anyone tell why and how to fix this? The $errors variable should always be there by Laravel standards...
The $errors variable should always be there by Laravel standards...
Unless you disable the middleware!
The feature is implemented by having the ShareErrorsFromSession being enabled; which you just disabled.
The answer at Temporarily disable / bypass Middleware has some pointers form here on.

Laravel 5.1 formfacade can't get value from select

I have created a form to change the user name and its role in the website.
#extends('layout/layoutAdmin')
#section('content')
<div>
<h1>{{ $user -> name }}<h1>
<p>{{ $user -> email }}<p>
</div>
{!! Form::model($user, ['url' => 'admin/menu/user_profiles/' . $user->id, 'method' => 'PATCH']) !!}
<div class="row">
<div class ="form-group">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', $user->name,['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('role', 'Role:') !!}
{!! Form::select('role', array('admin' => 'admin', 'super_admin' => 'super admin',
'super_researcher' => 'super researcher', 'researcher' => 'researcher',
'consultant' => 'consultant', 'user' => 'user'), $user->role)
!!}
</div>
<div class="form-group col-xs-8 col-md-7">
{!! Form::submit('Update', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
#stop
Everything is correct with the controller and I can change the name just fine, but I cannot save a new value for the role. it always stays the same.
Could anyone tell me how to save the role value?
EDIT!!!!
I did not have role field as fillable!

Categories