jonnybarnes.uk/app/Http/Controllers/Admin/NotesController.php
Jonny Barnes 3f15291d16 Update the app to Laravel 5.5
Squashed commit of the following:

commit 070f46bbacd91855730d467cc2806183441791ae
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Mon Sep 4 18:06:04 2017 +0100

    Now we now how the laravel IoC conatiner works, no need to be newing class dependencies

commit 57eeacdef178532a681f774f8c6738950d40c964
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Mon Sep 4 17:59:28 2017 +0100

    Get json test working again

commit 81c3cfc9b432241d8a4df7f1e0511a50ea4f9b90
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Mon Sep 4 14:38:10 2017 +0100

    Can’t use RefreshDatabase yet

commit 4ba5ff724d50ca86b3fa90c7bb4e71ad9e4dad79
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Mon Sep 4 14:10:33 2017 +0100

    Initial attempt at updating to Laravel 5.5
2017-09-04 19:34:39 +01:00

131 lines
3.2 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Note;
use Validator;
use Illuminate\Http\Request;
use App\Jobs\SendWebMentions;
use App\Services\NoteService;
use App\Http\Controllers\Controller;
class NotesController extends Controller
{
protected $noteService;
public function __construct(NoteService $noteService)
{
$this->noteService = $noteService;
}
/**
* List the notes that can be edited.
*
* @return \Illuminate\View\Factory view
*/
public function index()
{
$notes = Note::select('id', 'note')->orderBy('id', 'desc')->get();
foreach ($notes as $note) {
$note->originalNote = $note->getOriginal('note');
}
return view('admin.notes.index', compact('notes'));
}
/**
* Show the form to make a new note.
*
* @return \Illuminate\View\Factory view
*/
public function create()
{
return view('admin.notes.create');
}
/**
* Process a request to make a new note.
*
* @param Illuminate\Http\Request $request
* @todo Sort this mess out
*/
public function store(Request $request)
{
$validator = Validator::make(
$request->all(),
['photo' => 'photosize'],
['photosize' => 'At least one uploaded file exceeds size limit of 5MB']
);
if ($validator->fails()) {
return redirect('/admin/notes/create')
->withErrors($validator)
->withInput();
}
$data = [];
$data['content'] = $request->input('content');
$data['in-reply-to'] = $request->input('in-reply-to');
$data['location'] = $request->input('location');
$data['syndicate'] = [];
if ($request->input('twitter')) {
$data['syndicate'][] = 'twitter';
}
if ($request->input('facebook')) {
$data['syndicate'][] = 'facebook';
}
$note = $this->noteService->createNote($data);
return redirect('/admin/notes');
}
/**
* Display the form to edit a specific note.
*
* @param string The note id
* @return \Illuminate\View\Factory view
*/
public function edit($noteId)
{
$note = Note::find($noteId);
$note->originalNote = $note->getOriginal('note');
return view('admin.notes.edit', compact('note'));
}
/**
* Process a request to edit a note. Easy since this can only be done
* from the admin CP.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\View\Factory view
*/
public function update($noteId, Request $request)
{
//update note data
$note = Note::findOrFail($noteId);
$note->note = $request->input('content');
$note->in_reply_to = $request->input('in-reply-to');
$note->save();
if ($request->input('webmentions')) {
dispatch(new SendWebMentions($note));
}
return redirect('/admin/notes');
}
/**
* Delete the note.
*
* @param int id
* @return view
*/
public function destroy($id)
{
$note = Note::findOrFail($id);
$note->delete();
return redirect('/admin/notes');
}
}