2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2017-06-22 15:41:23 +01:00
|
|
|
use App\Note;
|
2016-11-22 16:08:02 +00:00
|
|
|
use Illuminate\Http\Request;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Jonnybarnes\IndieWeb\Numbers;
|
|
|
|
|
|
|
|
// Need to sort out Twitter and webmentions!
|
|
|
|
|
|
|
|
class NotesController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show all the notes.
|
|
|
|
*
|
2016-11-22 16:08:02 +00:00
|
|
|
* @param Illuminate\Http\Request request;
|
2016-05-19 15:01:28 +01:00
|
|
|
* @return \Illuminte\View\Factory view
|
|
|
|
*/
|
2017-02-15 18:39:39 +00:00
|
|
|
public function index(Request $request)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2017-06-22 14:30:10 +01:00
|
|
|
$notes = Note::orderBy('id', 'desc')
|
|
|
|
->with('place', 'media', 'client')
|
|
|
|
->withCount(['webmentions As replies' => function ($query) {
|
|
|
|
$query->where('type', 'in-reply-to');
|
|
|
|
}])->paginate(10);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2017-06-22 17:25:02 +01:00
|
|
|
return view('notes.index', compact('notes'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a single note.
|
|
|
|
*
|
|
|
|
* @param string The id of the note
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-15 18:39:39 +00:00
|
|
|
public function show($urlId)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2017-06-22 16:42:10 +01:00
|
|
|
$note = Note::nb60($urlId)->with('webmentions')->first();
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2017-06-22 16:42:10 +01:00
|
|
|
return view('notes.show', compact('note'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect /note/{decID} to /notes/{nb60id}.
|
|
|
|
*
|
|
|
|
* @param string The decimal id of he note
|
|
|
|
* @return \Illuminate\Routing\RedirectResponse redirect
|
|
|
|
*/
|
2017-02-15 18:39:39 +00:00
|
|
|
public function redirect($decId)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2017-06-22 15:57:31 +01:00
|
|
|
return redirect(config('app.url') . '/notes/' . (new Numbers())->numto60($decId));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show all notes tagged with {tag}.
|
|
|
|
*
|
|
|
|
* @param string The tag
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-15 18:39:39 +00:00
|
|
|
public function tagged($tag)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2016-05-29 13:49:30 +01:00
|
|
|
$notes = Note::whereHas('tags', function ($query) use ($tag) {
|
|
|
|
$query->where('tag', $tag);
|
|
|
|
})->get();
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2017-02-15 18:39:39 +00:00
|
|
|
return view('notes.tagged', compact('notes', 'tag'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
}
|