laravel lumen
1. cara menggunakan facedes db ( tambahkan di public )
Note: If you would like to use the DB facade, you should uncomment the $app->withFacades() call in your bootstrap/app.php file.
2. update quiery builder with array
https://stackoverflow.com/questions/29207055/use-an-array-in-laravel-update-query
3. cara relasi model lumen
ket : id ( untuk key local nya / ibu)
attribute_id ( untuk key cabang / anak)
public function attribute_data()
{
return $this->belongsTo(AttributeData::class,'id','attribute_id');
}
gunakan with
https://zzzul.medium.com/membuat-restful-api-dengan-laravel-c369cb54c7b6
4. lumen session
https://github.com/rummykhan/lumen-session-example
5. select didalam relasi
https://stackoverflow.com/questions/25628754/laravel-nested-relationships
6. setting config.database.php lumen
https://stackoverflow.com/questions/37215265/lumen-create-database-connection-at-runtime
7. memperbaiki error orderby di lumen
ambil config di vendor/laravel/lumen-framework , copy config/database.php
https://stackoverflow.com/questions/43776758/how-can-i-solve-incompatible-with-sql-mode-only-full-group-by-in-laravel-eloquen
8. php mailer
https://github.com/bennyekop/laravel-phpmailer
9. foreach request dengan key
https://stackoverflow.com/questions/40807075/how-to-get-the-key-from-a-laravel-form-request
11. Membuat lumen token
https://codelapan.com/post/membuat-rest-api-auth-register-login-dengan-lumen-8
14. librarry mengatasi cors
https://github.com/fruitcake/laravel-cors
15. membuat table di lumen
Ya, Anda dapat menggunakan Artisan untuk membuat tabel di Lumen. Berikut adalah langkah-langkah untuk membuat tabel menggunakan Artisan di Lumen:
1. Buka terminal atau command prompt dan masuk ke direktori proyek Lumen Anda.
2. Jalankan perintah `php artisan make:migration create_nama_table --create=nama` untuk membuat migration baru. Ganti `nama` dengan nama tabel yang ingin Anda buat.
Contoh: `php artisan make:migration create_users_table --create=users`
3. Buka file migration baru yang telah dibuat di direktori `database/migrations`. Pada file tersebut, Anda dapat menambahkan kolom-kolom yang ingin Anda tambahkan ke tabel tersebut.
Contoh:
````php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
```
Pada contoh di atas, kita menambahkan beberapa kolom seperti `name`, `email`, `password`, dan lain-lain ke dalam tabel `users`.
4. Jalankan perintah `php artisan migrate` untuk menjalankan migration. Perintah ini akan membuat tabel baru di dalam database yang telah ditentukan di file `.env`.
Jika Anda ingin membatalkan migration yang telah dijalankan, jalankan perintah `php artisan migrate:rollback`.
Dengan mengikuti langkah-langkah di atas, Anda dapat membuat tabel baru di Lumen menggunakan Artisan. Pastikan bahwa Anda telah memahami konsep migration pada Laravel agar dapat membuat tabel dengan benar dan efisien.
-----------------------------------------------------------
5. membuat basic auth di lumen
A. ini authenticate
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;
use App\Models\User2;
use Illuminate\Support\Facades\Hash;
class Authenticate
{
/**
* The authentication guard factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
// public function handle($request, Closure $next, $guard = null)
// {
// if ($this->auth->guard($guard)->guest()) {
// return response('Unauthorized.', 401);
// }
// return $next($request);
// }
public function handle($request, Closure $next)
{
// $hash = Hash::make('mastersakti');
// dd($hash);
// Ambil kredensial dari permintaan HTTP
$username = $request->getUser();
$password = $request->getPassword();
// Retrieve the user from database
$user = User2::where('username', $username)->first();
// Check if user exists and password is correct
if ($user && Hash::check($password, $user->password)) {
// User authenticated successfully
return $next($request);
} else {
// User authentication failed
return response()->json(['message' => 'Invalid credentials'], 401);
}
}
}
B. aktifkan bostrapnya
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
C. ini routernya
$router->group(['middleware' => 'auth'], function () use ($router) {
$router->get('/member', 'HomeController@index');
});
Komentar
Posting Komentar