Note that there are some explanatory texts on larger screens.

plurals
  1. PORedactor imageUpload and Laravel 4 Resource Controllers
    primarykey
    data
    text
    <p>I've seen several solutions for the Redactor imageUpload using a dedicated route, however I choose to use a resource controller to do all the routing.</p> <p>The markup:</p> <pre><code>&lt;div class="row"&gt; &lt;div class="large-12 columns"&gt; {{ Form::model($page, array('method' =&gt; 'put', 'route' =&gt; array('pages.update', $page-&gt;id), 'files' =&gt; true)) }} &lt;div class="row"&gt; &lt;div class="large-12 columns"&gt; {{ Form::label('title', 'Title') }} {{ Form::text('title') }} &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="large-12 columns"&gt; {{ Form::label('body', 'Content') }} {{ Form::textarea('body') }} &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="large-12 columns"&gt; {{ Form::submit('Save', array('class' =&gt; 'button')) }} &lt;a href="{{ URL::route('pages.index') }}" class="btn btn-large"&gt;Cancel&lt;/a&gt; &lt;/div&gt; {{ Form::close() }} &lt;/div&gt; &lt;/div&gt; &lt;script&gt; $(document).ready(function() { $(this).foundation(); $('#body').redactor({ iframe: true, css: "{{ url('sleddog-assets/stylesheets/app.css') }}", imageUpload: 'pages.edit' }); }); &lt;/script&gt; </code></pre> <p>The code:</p> <pre><code>class PagesController extends \BaseController { /** * Display a listing of the resource. * * @return Response */ public function index() { //$pages = Page::all(); //return $pages; return \View::make('admin.pages.pages')-&gt;with('pages', Page::all()); } /** * Show the form for creating a new resource. * * @return Response */ public function create() { return \View::make('admin.pages.create'); //return "Create"; } /** * Store a newly created resource in storage. * * @return Response */ public function store() { $validation = new PageValidator; if ($validation-&gt;passes()) { // $file = Input::file('file'); // if(Input::upload('file', 'public/images', $file['name'])) { // $image = Response::json(array('filelink' =&gt; 'images/' . $file['name'])); // } $page = new Page; $page-&gt;title = Input::get('title'); $page-&gt;slug = Str::get('slug'); $page-&gt;body = Input::get('body'); $page-&gt;user_id = Sentry::getUser()-&gt;id; $page-&gt;save(); return Redirect::route('admin.pages.edit'); } return Redirect::back()-&gt;withInput()-&gt;withErrors($validation-&gt;errors); } /** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { return \View::make('admin.pages.show')-&gt;with('page', Page::find($id)); } /** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { return \View::make('admin.pages.edit')-&gt;with('page', Page::find($id)); } /** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $validation = new PageValidator; if ($validation-&gt;passes()) { // $file = Input::file('file'); // if(Input::upload('file', 'public/images', $file['name'])) { // $image = Response::json(array('filelink' =&gt; 'images/' . $file['name'])); // } $page = Page::find($id); $page-&gt;title = Input::get('title'); $page-&gt;slug = Str::slug(Input::get('title')); $page-&gt;body = Input::get('body'); $page-&gt;user_id = Sentry::getUser(); $page-&gt;save(); return Redirect::route('pages.edit', $page-&gt;id); } return Redirect::back()-&gt;withInput()-&gt;withErrors($validation-&gt;errors); } /** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $page = Page::find($id); return Redirect::route('admin.pages.pages'); } } </code></pre> <p>My questions:</p> <p>In the markup, where do I aim the imageUpload? pages.edit? In the controller, where do put the code that is required to get Redactor's imageUpload to work?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload