#php #laravel-7
#php #laravel-7
Вопрос:
Я создаю свою собственную систему бронирования, и основной скрипт, который запрещает хранение данных в БД, не работает. Сам скрипт:
<?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());
}
}
}
И у меня есть эта схема БД
<?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');
}
}
И у меня даже есть маршруты, но я не думаю, что с ними есть какие-либо проблемы
<?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'
]);
Я тоже могу показать модель
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Order extends Model
{
public $fillable = ['name', 'phone', 'orderdatestart', 'orderdateend'];
}
Скрипт, который я пометил как основной, просто всегда отображает меня, я не позволю вам этого делать >:(
Мне нужно, когда один посетитель забронировал какую-то дату, эта дата будет заблокирована для бронирования
Комментарии:
1. Что вы имеете в виду под «не работает»? Вы видите в сообщениях об ошибках?
2. неа. Он просто всегда показывает мне, что я не позволю вам бронировать это >:(
Ответ №1:
Строка:
if(!empty($bookedDate and $bookedDate2)){
Выглядит очень подозрительно; должно ли это быть что-то вроде:
if(!empty($bookedDate) or !empty($bookedDate2)){
Вы хотите отказаться от бронирования, если какая-либо дата не пуста.
Комментарии:
1. Я изменил это так, проверьте сейчас, может быть, я что-то сделал неправильно