/codeigniter-Blade-Eloquent

Codeigniter + Blade + Eloquent

Primary LanguagePHPMIT LicenseMIT

Version Codeigniter 3.1.~

After "Git clone", you execute "composer install"

composer install

Usage Eloquent (example)

- DATABASE TEST (MYSQL) (NAME: users)

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  `email` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `users` (`id`, `username`, `password`, `email`) VALUES
(1, 'test_01', 'test', 'test_01@test.com'),
(2, 'test_02', 'test123', 'test_02@test.com'),
(3, 'test_03', 'test', 'test_03@test.com'),
(4, 'test_04', 'test123', 'test_04@test.com');

- Model (local: application/models - name: User.php)

<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

use \Illuminate\Database\Eloquent\Model;

class User extends Model {
    protected $table = "users";
}

- Controller (local: application/controllers - name: Home.php)

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use App\Core\BladeController;

class Home extends BladeController {

	public function __construct() {        
		parent::__construct();
	}

	public function index()
	{
		$users = User::all();

		$this->view('home', compact('users'));
	}

}

- View (local: application/views - name: home.blade.php)

    @foreach ($users as $value)
        <li>Username: {{ $value->username }}</li>
        <li>Email: {{ $value->email }}</li><br>
    @endforeach

- Blade Laravel (Documentation)

https://laravel.com/docs/5.8/blade