Laravel의 라우팅, 컨트롤러 및 모델
1 라우팅
\routes\web.php
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('basic1',function (){
return 'hello wor;d';
});
Route::get('user/{id}',function($id){
return 'User-'.$id;
});*/
/*Route::get('user/{name}',function($name=null){
return 'User-name-'.$name;
});*/
/*Route::get('user/name',['as'=>'name',function(){
return route('name');
}]);
Route::get('hello',function (){
return view('welcome');
});*/
/*Route::get('member/{info?}','MemberController@info');*/
Route::get('member/info',['uses' => 'MemberController@info']);
Route::get('test1',['uses'=>'StudentController@test1']);
Route::get('orm',['uses'=>'StudentController@orm']);
2 컨트롤러
app\Http\Controllers\StudentController.php
php
/**
* Created by PhpStorm.
* User: SUN
* Date: 2020/7/11
* Time: 18:43
*/
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Student;
class StudentController extends Controller
{
public function test1()
{
/* $i = DB::insert('insert into student(name ,age) values (?,?)', ['tt',18]);
$s = DB::select('select * from student');
dd($s);*/
//2
/* $i = DB::table('student')->insert(
['name'=>'imoocaaa','age'=>43]
);
dd($i);*/
/* $list = DB::table('student')->orderBy('id','desc')
->get();
dd($list);*/
/* $first = DB::table('student')->orderBy('id','desc')
->first();
dd($first);*/
/* $list = DB::table('student')
->where('age','<=',18)
->get();
dd($list);*/
// where
/* $list = DB::table('student')
->whereRaw('id >= ? and age >?',[1,18])
->get();
dd($list);*/
//pluck
/*$name = DB::table('student')
->pluck('name');
//->first();
dd($name);*/
/* $name = DB::table('student')
->pluck('id','name');
//->first();
dd($name);*/
/*$list = DB::table('student')
->select('id','name','age')
->get();
dd($list);*/
/* echo "";
DB::table('student')
->orderBy('id')
->chunk(2,function($students){
var_dump($students);
echo "-------------";
});
*/
$num = DB::table('student')->count();
var_dump($num);
$min = DB::table('student')->min('age');
$max = DB::table('student')->max('age');
$count = DB::table('student')->count();
$sum = DB::table('student')->sum('age');
dd($sum);
}
public function orm()
{
/*$list = Student::all();
dd($list);*/
//신규 데이터
/* $student = new Student();
$student->name = 'sean';
$student->age = '8';
$bool = $student->save();
dd($bool);*/
/* $comment = Student::find(5);
$comment->name = 'bbb';
$comment->test = date('Y-m-d H:i:s',time());
$bool = $comment->save();
echo($comment->updated_at);*/
//모델의create 방법으로 데이터 추가
/* $s = Student::create(['name'=>'imooc','age'=>18]);
dd($s);*/
/* $student = Student::firstOrCreate(
['name'=>'imoocaabb']
);
dd($student);*/
/*$student = Student::firstOrNew(
['name'=>'imoocjjaabb']
);
$student->save();
dd($student);*/
/*$num = Student::where('id','>',9)->update(
['age'=>44]
);
var_dump($num);*/
/* $bool= Student::where('id','>',9)->delete();
dd($bool);*/
/* $s = Student::find(8);
$bool = $s->delete();
dd($bool);*/
$d = Student::destroy(7,11);
dd($d);
}
}
3 모델
\app\Student.php php
/**
* Created by PhpStorm.
* User: SUN
* Date: 2020/7/11
* Time: 17:06
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
class Student extends Model
{
//public $timestamps = false;
protected $table = 'student';
protected $primaryKey = 'id';
//
//protected $fillable = ['name','age'];
//
//protected $guarded = [];
//protected $dateFormat = 'U';
/*protected function asDateTime($val)
{
return $val;
}*/
/* DB::table('student')->insert(
['name'=>'tt','age'=>18]
);*/
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.