Нашли причину segfault. Причина оказалось в том что декораторы при использовании динамического полиморфизма не обращались к базовым методам класса.
Синтаксис вызова базовых методов:
Синтаксис вызова базовых методов:
Class.Base::Update()
cmake . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DLINKS_PLATFORM_TESTS=TRUE
Конечно, вот как можно создать три миграции с помощью Artisan для описанных вами таблиц:
### Миграция 1: Создание таблицы "Жанры"
### Миграция 1: Создание таблицы "Жанры"
php artisan make:migration create_genres_tableОткройте сгенерированный файл миграции и добавьте следующий код:
use Illuminate\Database\Migrations\Migration;### Миграция 2: Создание таблицы "Фильмы"
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateGenresTable extends Migration
{
public function up()
{
Schema::create('genres', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('genres');
}
}
php artisan make:migration create_movies_tableОткройте сгенерированный файл миграции и добавьте следующий код:
use Illuminate\Database\Migrations\Migration;### Миграция 3: Создание таблицы связи "Фильмы с жанрами"
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMoviesTable extends Migration
{
public function up()
{
Schema::create('movies', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->enum('publication_status', ['published', 'unpublished'])->default('unpublished');
$table->string('poster_link')->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('movies');
}
}
php artisan make:migration create_movie_genre_tableОткройте сгенерированный файл миграции и добавьте следующий код:
use Illuminate\Database\Migrations\Migration;После создания миграций, выполните их, используя команду:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMovieGenreTable extends Migration
{
public function up()
{
Schema::create('movie_genre', function (Blueprint $table) {
$table->id();
$table->foreignId('movie_id')->constrained()->onDelete('cascade');
$table->foreignId('genre_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('movie_genre');
}
}
php artisan migrateТеперь у вас будут созданы три таблицы в базе данных: "genres", "movies" и "movie_genre", соответственно.
Task about website.
Font: Roboto 400 Regular
Max width of container is 1240px.
First element is picture with 1240x380
Second element is navbar with 1240x92px, also:
Logo inside on left side 169.02x45px
Location address inside 165x36px
Phone number inside 151x36px
Social network links 4 logo 176x32px, every logo is 32x32px
Last item on the right is button 156x32px
Continue...
Font: Roboto 400 Regular
Max width of container is 1240px.
First element is picture with 1240x380
Second element is navbar with 1240x92px, also:
Logo inside on left side 169.02x45px
Location address inside 165x36px
Phone number inside 151x36px
Social network links 4 logo 176x32px, every logo is 32x32px
Last item on the right is button 156x32px
Continue...
Давайте начнем с выполнения вашего задания. Для этого проекта мы создадим миграции, сиды, модели и контроллеры. Также добавим валидацию и загрузку изображений.
### Шаг 1: Создание миграций
1. Миграция для таблицы `genres`:
2. Миграция для таблицы `movies`:
3. Миграция для таблицы `genre_movie` (таблица связи):
Теперь заполним эти миграции.
database/migrations/xxxx_xx_xx_create_genres_table.php:
database/migrations/xxxx_xx_xx_create_movies_table.php:
database/migrations/xxxx_xx_xx_create_genre_movie_table.php:
### Шаг 2: Создание сидов
Создадим сиды для тестового заполнения таблиц.
database/seeders/GenreSeeder.php:
database/seeders/MovieSeeder.php:
database/seeders/DatabaseSeeder.php:
### Шаг 3: Создание моделей
app/Models/Genre.php:
app/Models/Movie.php:
### Шаг 1: Создание миграций
1. Миграция для таблицы `genres`:
php artisan make:migration create_genres_table
2. Миграция для таблицы `movies`:
php artisan make:migration create_movies_table
3. Миграция для таблицы `genre_movie` (таблица связи):
php artisan make:migration create_genre_movie_table
Теперь заполним эти миграции.
database/migrations/xxxx_xx_xx_create_genres_table.php:
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateGenresTable extends Migration
{
public function up()
{
Schema::create('genres', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('genres');
}
}
database/migrations/xxxx_xx_xx_create_movies_table.php:
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMoviesTable extends Migration
{
public function up()
{
Schema::create('movies', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->boolean('is_published')->default(false);
$table->string('poster_url')->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('movies');
}
}
database/migrations/xxxx_xx_xx_create_genre_movie_table.php:
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateGenreMovieTable extends Migration
{
public function up()
{
Schema::create('genre_movie', function (Blueprint $table) {
$table->id();
$table->foreignId('genre_id')->constrained()->onDelete('cascade');
$table->foreignId('movie_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('genre_movie');
}
}
### Шаг 2: Создание сидов
Создадим сиды для тестового заполнения таблиц.
database/seeders/GenreSeeder.php:
use Illuminate\Database\Seeder;
use App\Models\Genre;
class GenreSeeder extends Seeder
{
public function run()
{
Genre::create(['name' => 'Action']);
Genre::create(['name' => 'Comedy']);
Genre::create(['name' => 'Drama']);
}
}
database/seeders/MovieSeeder.php:
use Illuminate\Database\Seeder;
use App\Models\Movie;
class MovieSeeder extends Seeder
{
public function run()
{
Movie::create([
'title' => 'Movie 1',
'is_published' => false,
'poster_url' => 'default_poster.png'
]);
Movie::create([
'title' => 'Movie 2',
'is_published' => true,
'poster_url' => 'default_poster.png'
]);
}
}
database/seeders/DatabaseSeeder.php:
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(GenreSeeder::class);
$this->call(MovieSeeder::class);
}
}
### Шаг 3: Создание моделей
app/Models/Genre.php:
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Genre extends Model
{
use HasFactory;
protected $fillable = ['name'];
public function movies()
{
return $this->belongsToMany(Movie::class);
}
}
app/Models/Movie.php:
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Movie extends Model
{
use HasFactory;
protected $fillable = ['title', 'is_published', 'poster_url'];
public function genres()
{
return $this->belongsToMany(Genre::class);
}
}
### Шаг 4: Создание контроллеров
app/Http/Controllers/GenreController.php:
app/Http/Controllers/MovieController.php:
### Шаг 5: Настройка маршрутов
routes/api.php:
Это базовая структура для выполнения вашего задания. Вы можете дополнительно кастомизировать и улучшать код по мере необходимости.
app/Http/Controllers/GenreController.php:
namespace App\Http\Controllers;
use App\Models\Genre;
use Illuminate\Http\Request;
class GenreController extends Controller
{
public function index()
{
return Genre::all();
}
public function show($id)
{
return Genre::with('movies')->findOrFail($id);
}
// Other CRUD methods...
}
app/Http/Controllers/MovieController.php:
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class MovieController extends Controller
{
public function index()
{
return Movie::paginate(10);
}
public function show($id)
{
return Movie::with('genres')->findOrFail($id);
}
public function store(Request $request)
{
$request->validate([
'title' => 'required|string|max:255',
'poster' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
]);
$posterPath = $request->file('poster') ? $request->file('poster')->store('posters') : 'default_poster.png';
$movie = Movie::create([
'title' => $request->input('title'),
'poster_url' => $posterPath,
'is_published' => false
]);
return response()->json($movie, 201);
}
public function update(Request $request, $id)
{
$movie = Movie::findOrFail($id);
$request->validate([
'title' => 'required|string|max:255',
'poster' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
]);
if ($request->hasFile('poster')) {
Storage::delete($movie->poster_url);
$posterPath = $request->file('poster')->store('posters');
$movie->poster_url = $posterPath;
}
$movie->title = $request->input('title');
$movie->save();
return response()->json($movie, 200);
}
public function destroy($id)
{
$movie = Movie::findOrFail($id);
Storage::delete($movie->poster_url);
$movie->delete();
return response()->json(null, 204);
}
public function publish($id)
{
$movie = Movie::findOrFail($id);
$movie->is_published = true;
$movie->save();
return response()->json($movie, 200);
}
}
### Шаг 5: Настройка маршрутов
routes/api.php:
use App\Http\Controllers\GenreController;
use App\Http\Controllers\MovieController;
Route::get('genres', [GenreController::class, 'index']);
Route::get('genres/{id}', [GenreController::class, 'show']);
Route::get('movies', [MovieController::class, 'index']);
Route::get('movies/{id}', [MovieController::class, 'show']);
Route::post('movies', [MovieController::class, 'store']);
Route::put('movies/{id}', [MovieController::class, 'update']);
Route::delete('movies/{id}', [MovieController::class, 'destroy']);
Route::post('movies/{id}/publish', [MovieController::class, 'publish']);
Это базовая структура для выполнения вашего задания. Вы можете дополнительно кастомизировать и улучшать код по мере необходимости.

