I’m making my own booking system and the main script that denies storing data in DB is not working. The script itself:
<?php namespace AppHttpControllers; use AppRulesTaken; use IlluminateHttpRequest; use AppOrder; class orderController extends Controller { // Create Contact Form public function setOrder(Request $request) { return view('welcome'); } // Store Contact Form data public function order(Request $request) { $request->validate([ 'name' => [ 'required', ], 'phone' => [ 'required', ], 'orderdatestart' => [ 'required', 'date_format:Y-m-d', new Taken(), ], 'orderdateend' => [ 'required', 'date_format:Y-m-d', 'after:orderdatestart', new Taken(), ] ] ); // The main script that s not working -----> if (Order::where([ ['orderdatestart', '<=', $request['orderdatestart']], ['orderdateend', '>=', $request['orderdateend']] ])) { return "i wont let you do this >:("; }else{ Order::create($request->all()); } } }
And I have this Schema of DB
<?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateOrdersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('orders', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('phone'); $table->date('orderdatestart'); $table->date('orderdateend'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('orders'); } }
And I even have routes but I don’t think that there s any problems with them
<?php use IlluminateSupportFacadesRoute; /* |-------------------------------------------------------------------------- | 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'); }); // Render in view Route::get('/', [ 'uses' => 'orderController@setOrder' ]); // Post form data Route::post('/', [ 'uses' => 'orderController@order', 'as' => 'order.store' ]);
I can show the model too
<?php namespace App; use IlluminateDatabaseEloquentModel; class Order extends Model { public $fillable = ['name', 'phone', 'orderdatestart', 'orderdateend']; }
The script that I marked as main just always display me I won’t let you do this >:(
I need when one visiter has booked some date this date will be blocked from booking
Advertisement
Answer
The line:
if(!empty($bookedDate and $bookedDate2)){
Looks very suspicious; should that be something like:
if(!empty($bookedDate) or !empty($bookedDate2)){
You want to refuse to book if either date is not empty.