/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $devices = Device::orderBy('updated_at', 'desc')->get();
     return view('devices.index', compact('devices'));
 }
Example #2
0
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
use App\Device;
use Illuminate\Http\Request;
/**
 * Show Device Dashboard
 */
Route::get('/', function () {
    return view('devices', ['devices' => Device::orderBy('created_at', 'asc')->get()]);
});
/**
 * Add New Device
 */
Route::post('/device', function (Request $request) {
    $validator = Validator::make($request->all(), ['name' => 'required|max:255']);
    if ($validator->fails()) {
        return redirect('/')->withInput()->withErrors($validator);
    }
    $device = new Device();
    $device->name = $request->name;
    $device->save();
    return redirect('/');
});
/**
 /**
  * Get all devices ordered by the specified column.
  * @param  String $column Column from a database table.
  * @return Collection         Collection of devices.
  */
 public function orderBy($column)
 {
     return \App\Device::orderBy($column)->get();
 }