Skip to content

Instantly share code, notes, and snippets.

@bosz
Created April 27, 2020 14:48
Show Gist options
  • Save bosz/b81ec2626bfa1aa9300a8906ca77731c to your computer and use it in GitHub Desktop.
Save bosz/b81ec2626bfa1aa9300a8906ca77731c to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Subject;
class SubjectController extends Controller
{
public function index(){
$subjects = Subject::all();
return view('subjects')
->with('subjects', $subjects);
}
public function add(Request $request) {
$subject = new Subject;
$subject->name = 'Philosphy';
$subject->description = 'Study of man psychology';
$subject->save();
}
public function show($id) {
$subject = Subject::find($id);
$subject = Subject::where('id', $id)->first();
dd($subject->name);
}
public function delete($id)
{
Subject::where('id', $id)->delete();
}
}
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/about', function() {
return view('about');
});
Route::get('/subjects', 'SubjectController@index');
Route::get('/subjects/add', 'SubjectController@add'); // change from get to post
Route::get('/subjects/{id}', 'SubjectController@show');
Route::get('/subjects/{id}/delete', 'SubjectController@delete'); // change from get to delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment