I am very at beginning in laravel and currently trying to take input to search in database, and later use it in insert method, but I am constantly taking the same "method is not supported for route GET. Supported methods: POST." error My codes are :
web.php method;
Route::post('DevamsizlikList',[AttendaceController::class,'Yoklamainsert']);
model file;
class DevamsizlikList extends Model
{
protected $table = 'YOKLAMA';
use HasFactory;
}
controller file;
<?php
namespace App\Http\Controllers;
use App\Models\DevamsizlikList;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AttendanceController extends Controller
{
public function Yoklamainsert(Request $request)
{
$id = $request->input('id');
$attendence = $request->input('attendence');
$ogrtmn = $request->input('ogretmen_id');
$students = DB::table('OGRENCI')::query()
->select('ad', 'orta_Ad','soyad','ogretım_y','yariyil')
->where('OGR_NO'== $id)
->get();
$data = [
'ad' => $students->name,
'orta_ad' => $students->orta_ad,
'soyad' => $students->surname,
'ogretım_y' => $students->ogretım_y,
'yariyil' => $students->yariyil,
'devamsizlik' => $attendence,
'OGRTMN_SCL' => $ogrtmn
];
//insert data to database
DB::table('YOKLAMA')->insert([
'OGR_NO' => $id,
'ad' => $data['ad'],
'orta_ad' => $data['orta_ad'],
'soyad' => $data['soyad'],
'ogretım_y' => $data['ogretım_y'],
'tarih' => Carbon::createFromFormat('Y-m-d', date('Y-m-d')),
'yariyil' => $data['yariyil'],
'devamsizlik' => $data['devamsizlik'],
'OGRTMN_SCL' => $data['OGRTMN_SCL']
]);
}
}
I tried writing the method in web.php in form of `Route::post('/search',function(Request $request){
}); ` but it didn't work well too. can someone help me?
CodePudding user response:
If you change class name AttendaceController::class to AttendanceController::class and its not working then check, have you included this class to web.php
use App\Http\Controllers\AttendanceController;
CodePudding user response:
change this
Route::post('DevamsizlikList',[AttendaceController::class,'Yoklamainsert']);
to
Route::get('DevamsizlikList',[AttendaceController::class,'Yoklamainsert']);
or change the form method to post