<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class NotM4a implements Rule
{
public function passes($attribute, $value)
{
if (pathinfo($value->getClientOriginalName())['extension'] == "m4a") {
return false;
}
return true;
}
public function message()
{
return '.m4a files is not allowed to upload';
}
}
...
"rules" => [
...
new \App\Rules\NotM4a()
]
server {
client_max_body_size 256M;
server_name site.com www.site.com;
root /var/www/site/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location ~\.m4a$ {
deny all;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
<?php
namespace Naxon\UrlUploadedFile;
use Illuminate\Http\UploadedFile;
use Naxon\UrlUploadedFile\Exceptions\CantOpenFileFromUrlException;
class UrlUploadedFile extends UploadedFile
{
public static function createFromUrl(string $url, string $originalName = '', string $mimeType = null, int $error = null, bool $test = false): self
{
if (! $stream = @fopen($url, 'r')) {
throw new CantOpenFileFromUrlException($url);
}
$tempFile = tempnam('/var/www/transfer/storage/app/public/tmp', 'url-file-'); // путь в классе другой, указал свой для удобства отслеживания момента отвала
file_put_contents($tempFile, $stream);
return new static($tempFile, $originalName, $mimeType, $error, $test);
}
}
$file = UrlUploadedFile::createFromUrl($url);
$result = $file->storeAs('public/videos/', $file_name);
public function reply() {
return $this->hasOne(Comment::class, 'child_id');
}
public function replies() {
return $this->hasMany(Comment::class, 'child_id');
}
$comments = Comment::whereIn('id', [1200,1198,1195])->with([
'reply',
'replies' => function($query) {
$query->take(2);
}
])->get()->pluck('replies');