Laravel using Controller@show return view and api
<p>I am making a web application that will also be turned into a native app so I want to show json from one path and return a view for another path. Here is what I was thinking but not sure how to write the <code>if</code> statements in Laravel:</p>

<p>Routes.php</p>

<pre><code>Route::group(['middleware' =&gt; 'web'], function () {
    Route::auth();

    Route::get('/notes', 'NotesController@index');
    Route::get('/notes/{note}', 'NotesController@show');
    Route::get('api/notes/{note}', 'NotesController@show');
});
</code></pre>

<p>NotesController.php</p>

<pre><code>&lt;?php

namespace App\Http\Controllers;

use App\Note;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class NotesController extends Controller
{

    public function index() {

        $notes = Note::all();

        return view('notes.index', compact('notes'));
    }

    public function show(Note $note) {

        //if its from the general path show view
        return view('notes.show', compact('note'));

        //if its from the api path show json
        return $note;

    }

}
</code></pre>