Is that your whole SlidersController file, cos it looks like you are missing the class closing brace at the end }
Creating Laravel 5.7 dynamic Sliders in Laracom Ecommerce
Hi i am trying to add dynamic sliders in Laracom Ecommerce package by @jsdecena on github. I have created all the necessary spaces but I am getting the following error, when I try accessing the project.test/admin/slides page;
Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "syntax error, unexpected 'public' (T_PUBLIC)"
C:\laragon\www\laracom\app\Http\Controllers\Admin\slides\SliderController.php
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
{
$slider = slider::findorfail($ID);
return view('admin.slides.edit', compact('slider'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$slider = slider::find($id);
@$this->validate($request, array(
'title'=>'required|max:225',
'photo'=>'required|image'
));
$slider = slider::where('id',$id)->first();
$slider->title = $request->input('title');
if ($request->hasfile('photo')) {
$photo = $request->file('photo');
$filename = 'slide' . '-' . time() . '.' . $photo->getclientoriginalextension();
$location = public_path('images/');
$request->file('photo')->move($location, $filename);
$oldfilename = $slider->photo;
$sliders->photo= $filename;
IF(!EMPTY($slider->photo)){
Arguments
"syntax error, unexpected 'public' (T_PUBLIC)"
Below is my SlidersController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Shop\Slider\Slider;
use App\Shop\Categories\Requests\UpdateCategoryRequest;
class SliderController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
// index function
public function index()
{
$sliders = Slider::orderby('id', 'desc')->paginate(10);
return view('sliders.index', compact('sliders'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view ('admin.slides.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, array(
'title'=>'required|max:225',
'photo'=>'required|image',
));
$slider = new Slider;
$slider->title = $request->input('title');
if ($request->hasFile('photo')) {
$photo = $request->file('photo');
$filename = 'slide' . '-' . time() . '.' . $photo->getClientOriginalExtension();
$location = public_path('images/');
$request->file('photo')->move($location, $filename);
$slider->photo = $filename;
}
$slider->save();
return redirect()->route('admin.slides.index');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
{
$slider = slider::findorfail($ID);
return view('admin.slides.edit', compact('slider'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdateSlideRequest $request, $id)
{
$slider = slider::find($id);
@$this->validate($request, array(
'title'=>'required|max:225',
'photo'=>'required|image'
));
$slider = slider::where('id',$id)->first();
$slider->title = $request->input('title');
if ($request->hasfile('photo')) {
$photo = $request->file('photo');
$filename = 'slide' . '-' . time() . '.' . $photo->getclientoriginalextension();
$location = public_path('images/');
$request->file('photo')->move($location, $filename);
$oldfilename = $slider->photo;
$sliders->photo= $filename;
IF(!EMPTY($slider->photo)){
storage::delete($oldfilename);
}
}
$slider->save();
return redirect()->route('slides.index',
$slider->id)->with('success',
'slider, '. $slider->style.' updated');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$slider = slider::findorfail($id);
storage::delete($slider->photo);
$slider->delete();
return redirect()->route('admin.slides.index')
->with('success',
'Slide has been successfully deleted');
}
my slider model (slider.php)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Slider extends Model
{
//
protected $fillable = [
'title', 'photo',
];
}
views/admin/slides/index.blade.php
<a href="{{ route('admin.slide.create') }}">Add New Slide</a>
<div style="margin-top:30px;">
@foreach($sliders as $slider)
<
<img src="{{url('images')}}/{{$slider->photo}}" alt="{{$slider->title}}" width="250" height="150">
<a href="{{ route('admin.slide.edit', $slider->id) }}" class="btn btn-block btn-info">Edit Slide</a>
{!! form::open(['method' => 'delete', 'route' => ['admin.slides.destroy', $slider->id] ]) !!}
<button class="btn btn-block btn-danger" type="submit">Delete</button>
{!! form::close() !!}
<br>
@endforeach
</div>
views/admin/create.blade.php
{{ Form::open(array('route' => 'slides.store', 'files' => true)) }}
{{ Form::label('title', 'Title') }}
{{ Form::text('title', null, array('class' => 'form-control')) }}
{{ Form::label('photo', 'Photo') }}
{{ Form::file('photo', array('class' => 'form-control')) }}
{{ Form::submit('Add', array('class' => 'pull-right btn btn-primary')) }}
{{ Form::close() }}
views/admin/edit.blade.php;
{{ FORM::MODEL($SLIDER, ARRAY('ROUTE' => ARRAY('SLIDES.UPDATE', $SLIDER->ID), 'METHOD' => 'PUT', 'FILES' => TRUE)) }}
{{FORM::LABEL('TITLE', 'TITLE')}}
{{FORM::TEXT('TITLE', NULL, ARRAY('CLASS' => 'FORM-CONTROL'))}}
<BR>
{{FORM::LABEL('PHOTO', 'PHOTO')}}
{{FORM::FILE('PHOTO', ARRAY('CLASS' => 'FORM-CONTROL'))}}
<BR>
<IMG SRC="{{URL('IMAGES')}}/{{$SLIDER->PHOTO}}" ALT="IMAGE">
<BR><BR><BR>
{{ FORM::SUBMIT('UPDATE SLIDE', ARRAY('CLASS' => 'BTN BTN-SUCCESS')) }}
{{FORM::CLOSE()}}
Any assistance will be greatly appreciated. Thanks
@hackroot I've been through your files and got it all working. You did have a reference to Form Helper in your edit view. There was a quite a few things to correct as you had half changed some of the forms you'd based this off, but there were references to categories in admin.slides.index and some missing stuff all around.
Heres my branch based of laracom master. You'll have all the admin functionality here now, and image 'slides' being dropped into your home page view.
https://github.com/jsdecena/laracom/compare/master...iammikek:feature/slides
Please or to participate in this conversation.