I'm new to learning Laravel 5. I'm following a tutorial and I have the following code in my controller. What I want is to update the username with ID=10 in my login database. I follow the tutorial and also the Laravel documentation but what happens is it inserts another record instead of updating the existing. What is wrong with my code?
Routes.php:
Route::get('/users', "PagesController@login");
login.php (model)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class login extends Model
{
public $timestamps = false;
protected $table = 'login';
protected $fillable = [
'username',
'password'
];
}
PagesController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\login; //added
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PagesController extends Controller
{
public function login()
{
$login = new login;
$login::find(10);
$login->username ='updated_username';
$login->save();
}
}
var_dump($login);after$login::find(10);?php artisan tinkerand then type the code and see the result there itself