All settings correct for using Composer
Downloading...
Composer (version 2.6.6) successfully installed to: /home/kokaki/www/laravel/composer.phar
Use it: php composer.phar
kokaki@skynew:~/www/laravel$ sudo mv composer.phar /usr/local/bin/composer
PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies
6.Composerを使用してLaravelをインストールする
51 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
INFO Discovering packages.
laravel/sail ....................................................................................................... DONE
laravel/sanctum .................................................................................................... DONE
laravel/tinker ..................................................................................................... DONE
nesbot/carbon ...................................................................................................... DONE
nunomaduro/collision ............................................................................................... DONE
nunomaduro/termwind ................................................................................................ DONE
spatie/laravel-ignition ............................................................................................ DONE
83 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
INFO No publishable resources for tag [laravel-assets].
No security vulnerability advisories found.
> @php artisan key:generate --ansi
INFO Application key set successfully.
7.Laravelサーバーを実行する
'timezone' => 'Asia/Tokyo',
'locale' => 'ja',
'fallback_locale' => 'ja',
'faker_locale' => 'ja_JP',
kokaki@skynew:~/www/laravel/testapp$ vi .env
APP_NAME=Laravel_TodoApp
・データベースとの接続
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=dev
DB_PASSWORD=dev
※MySQLにデータベース「laravel」を作成しておく!
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
kokaki@skynew:~/www/laravel/testapp$ php artisan config:clear
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->boolean('status')->default(false);
$table->timestamp('updated_at')->useCurrent()->nullable();
$table->timestamp('created_at')->useCurrent()->nullable();
});
kokaki@skynew:~/www/laravel/testapp$ php artisan migrate
use App\Http\Controllers\TaskController;
Route::resource('tasks', TaskController::class);
kokaki@skynew:~/www/laravel/testapp$ php artisan route:list
GET|HEAD / ..................................................................................................
POST _ignition/execute-solution ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionContr…
GET|HEAD _ignition/health-check ....... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
POST _ignition/update-config .... ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
GET|HEAD api/user ...........................................................................................
GET|HEAD sanctum/csrf-cookie .............. sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
GET|HEAD tasks ........................................................... tasks.index › TaskController@index
POST tasks ........................................................... tasks.store › TaskController@store
GET|HEAD tasks/create .................................................. tasks.create › TaskController@create
GET|HEAD tasks/{task} ...................................................... tasks.show › TaskController@show
PUT|PATCH tasks/{task} .................................................. tasks.update › TaskController@update
DELETE tasks/{task} ................................................ tasks.destroy › TaskController@destroy
GET|HEAD tasks/{task}/edit ................................................. tasks.edit › TaskController@edit
Showing [13] routes
kokaki@skynew:~/www/laravel/testapp$ mkdir resources/views/tasks
public function index()
{
return view('tasks.index');
}
kokaki@skynew:~/www/laravel/testapp$ php artisan serve
Alias /laravel-testapp /home/kokaki/www/laravel/testapp/public/
<Directory "/home/kokaki/www/laravel/testapp/public/">
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Require all granted
#Order allow,deny
#Allow from all
</Directory>
kokaki@skynew:~$ sudo a2ensite laravel
<form action="/tasks" method="post" ・・・
↓
<form action="{{ url('/tasks') }}" method="post" ・・・
<form action="/tasks/{{ $task->id }}" method="post" ・・・
↓
<form action="{{ url('/tasks')}}/{{ $item->id }}" method="post" ・・・
・セッション情報の権限問題
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
・.envファイルの編集
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel10
DB_USERNAME=root
DB_PASSWORD=
↓
DB_CONNECTION=sqlite
・php artisan migrateでテーブルの作成
Illuminate\Database\QueryException
could not find driver (Connection: sqlite, SQL: PRAGMA foreign_keys = ON;)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:829
825▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
826▕ );
827▕ }
828▕
➜ 829▕ throw new QueryException(
830▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
831▕ );
832▕ }
833▕ }
+40 vendor frames
41 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
※エラーが発生
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
php8.1-sqlite3
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.2 kB of archives.
After this operation, 139 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 php8.1-sqlite3 amd64 8.1.2-1ubuntu2.14 [32.2 kB]
Fetched 32.2 kB in 1s (34.3 kB/s)
Selecting previously unselected package php8.1-sqlite3.
(Reading database ... 72071 files and directories currently installed.)
Preparing to unpack .../php8.1-sqlite3_8.1.2-1ubuntu2.14_amd64.deb ...
Unpacking php8.1-sqlite3 (8.1.2-1ubuntu2.14) ...
Setting up php8.1-sqlite3 (8.1.2-1ubuntu2.14) ...
Creating config file /etc/php/8.1/mods-available/sqlite3.ini with new version
Creating config file /etc/php/8.1/mods-available/pdo_sqlite.ini with new version
Processing triggers for libapache2-mod-php8.1 (8.1.2-1ubuntu2.14) ...
Processing triggers for php8.1-cli (8.1.2-1ubuntu2.14) ...
kokaki@skynew:~/www/laravel/testapp$ sudo service apache2 restart
INFO Preparing database.
Creating migration table ................................................................................. 14ms DONE
INFO Running migrations.
2014_10_12_000000_create_users_table ..................................................................... 28ms DONE
2014_10_12_100000_create_password_reset_tokens_table ..................................................... 12ms DONE
2019_08_19_000000_create_failed_jobs_table ............................................................... 24ms DONE
2019_12_14_000001_create_personal_access_tokens_table .................................................... 27ms DONE
2024_02_07_133544_create_tasks_table ...................................................................... 9ms DONE
・アプリケーションで使用時、エラーが発生
SQLSTATE[HY000]: General error: 8 attempt to write a readonly database
・データベースファイルの書き込み権限を追加
:
:
:
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
INFO No publishable resources for tag [laravel-assets].
No security vulnerability advisories found.
> @php artisan key:generate --ansi
INFO Application key set successfully.
■権限設定(オーナー)
'timezone' => 'Asia/Tokyo',
'locale' => 'ja',
'fallback_locale' => 'ja',
'faker_locale' => 'ja_JP',
■データベース設定
#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=laravel
#DB_USERNAME=root
#DB_PASSWORD=
DB_CONNECTION=sqlite
■プロジェクト実行
INFO Migration [database/migrations/2024_02_16_092723_create_tasks_table.php] created successfully.
kokaki@skynew:~/www/laravel/todo2$ vi database/migrations/2024_02_16_092723_create_tasks_table.php
public function up(): void
{
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->boolean('status')->default(false);
$table->timestamp('updated_at')->useCurrent()->nullable();
$table->timestamp('created_at')->useCurrent()->nullable();
});
}
kokaki@skynew:~/www/laravel/todo2$ php artisan migrate
WARN The SQLite database does not exist: database/database.sqlite.
┌ Would you like to create it? ────────────────────────────────┐
│ Yes │
└──────────────────────────────────────────────────────────────┘
INFO Preparing database.
Creating migration table ................................................................................. 15ms DONE
INFO Running migrations.
2014_10_12_000000_create_users_table ..................................................................... 21ms DONE
2014_10_12_100000_create_password_reset_tokens_table ...................................................... 8ms DONE
2019_08_19_000000_create_failed_jobs_table ............................................................... 18ms DONE
2019_12_14_000001_create_personal_access_tokens_table .................................................... 26ms DONE
2024_02_16_092723_create_tasks_table ..................................................................... 10ms DONE
■モデルを作る
INFO Model [app/Models/Task.php] created successfully.
kokaki@skynew:~/www/laravel/todo2$ php artisan make:controller TaskController --resource
INFO Controller [app/Http/Controllers/TaskController.php] created successfully.
■ルーティング情報
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TaskController; // 追加
Route::get('/', function () {
return view('welcome');
});
Route::resource('tasks', TaskController::class); // 追加
kokaki@skynew:~/www/laravel/todo2$ php artisan route:list
GET|HEAD / ..................................................................................................
POST _ignition/execute-solution ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionContr…
GET|HEAD _ignition/health-check ....... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
POST _ignition/update-config .... ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
GET|HEAD api/user ...........................................................................................
GET|HEAD sanctum/csrf-cookie .............. sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
GET|HEAD tasks ........................................................... tasks.index › TaskController@index
POST tasks ........................................................... tasks.store › TaskController@store
GET|HEAD tasks/create .................................................. tasks.create › TaskController@create
GET|HEAD tasks/{task} ...................................................... tasks.show › TaskController@show
PUT|PATCH tasks/{task} .................................................. tasks.update › TaskController@update
DELETE tasks/{task} ................................................ tasks.destroy › TaskController@destroy
GET|HEAD tasks/{task}/edit ................................................. tasks.edit › TaskController@edit
Showing [13] routes
kokaki@skynew:~/www/laravel/todo2$ mkdir resources/views/tasks
tasks
論理名 |物理名 |型 |制約 |補足
ID |id |bigserial |not null|pk
タスク名 |title |character varying(40) |not null|
ステータス|ststus |integer |not null|
概要 |description|character varying(200)| |
作成日 |created_at |timestamp | |
更新日 |updated_a t|timestamp | |
create table tasks (
id integer not null primary key
, title var(40) not null
, status integer not null
, description varchar(200)
, created_at timestamp
, updated_at timestamp
) ;
Schema::create('todos', function (Blueprint $table) {
$table->id();
$table->string('title', 40);
$table->boolean('status')->default(false);
$table->string('description', 200);
$table->timestamp('created_at')->useCurrent()->nullable();
$table->timestamp('updated_at')->useCurrent()->nullable();
});
INSERT INTO tasks (title,status,description) VALUES ('bitcoinの半減期を調べる',1,'bitcoinの半減期と価格の相関性を調べる');
INSERT INTO tasks (title,status,description) VALUES ('サンフランシスコ旅行',1,'サンノゼ空港からパロ・アルトへの行き方を調べる');
INSERT INTO tasks (title,status,description) VALUES ('アクアパッツァ',1,'再来週の食事会のためにアクアパッツァの作り方を学ぶ');
INSERT INTO tasks (title,status,description) VALUES ('サンフランシスコ行きの航空券',1,'羽田からサンノゼ空港行きのチケットを予約');
2025 kokaki.jp, Office.