$.ajax({
method: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
$name = $_POST["name"];
$location = $_POST["location"];
var_dump($name, $location);
fetch ("some.php",{
body: "name=" + encodeURIComponent("John") + "&location=" + encodeURIComponent("Boston")
cache: "default",
headers: {'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'},
method: "POST",
mode: "cors"
}).then( (response) => {
if (response.status !== 200) {
return Promise.reject();
}
return response["text"]();
}).then(msg=>{
alert( "Data Saved: " + msg );
})
папочки vendor и node_modules отсутсуют, точно так же, как и файл .env
class A
{
private static array $instances = [];
public readonly int $value;
public function __construct(?int $value = null)
{
if ($value !== null) {
$this->value = $value;
static::$instances[] = $this;
}
}
public function summ(): int
{
return array_reduce(
static::$instances,
fn($acc, $cur) => $acc + $cur->value,
0
);
}
}
new A(2);
new A(3);
$summ = (new A())->summ();
print $summ; // 5
class Single
{
public array $data = [];
public static $instance;
PRIVATE function __construct()
{
}
public static function getInstance()
{
if (empty(self::$instance)) {
self::$instance = new Single();
}
return self::$instance;
}
public function __get(string $key)
{
return $this->data[$key]??null;
}
public function __set(string $key, $value)
{
$this->data[$key] = $value;
}
}
class A
{
public static function tryW()
{
Single::getInstance()->some = 1;
}
}
class B
{
public static function tryR()
{
var_dump(Single::getInstance()->some);
}
}
$a = new A();
$a->tryW();
$b = new B();
$b->tryR();
-Был ли у вас хоть какой то опыт работы со сторонними апи?
-Да
-Расскажите как бы вы реализовали API получения курсов валютных котировок. Какие подводные камни?
git branch --unset-upstream [локальная_ветка]
git remote remove origin
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'category_product', 'category_id', 'product_id');
}
Schema::create('category_product', function (Blueprint $table) {
$table->primary(['category_id', 'product_id']);
$table->foreignId('category_id')->nullable();
$table->foreignId('product_id')->nullable();
});