Oracle Eloquent Model
Extend Laravel-OCI8's OracleEloquent class to unlock Oracle-specific features in your Eloquent models.
Benefits of OracleEloquent
- Automatic BLOB handling: Set binary fields directly as model attributes
- Sequence management: Built-in support for Oracle sequences
- Oracle-specific optimizations: Tailored for Oracle database features
Basic Usage
Defining a Model
<?php namespace App\Models; use Yajra\Oci8\Eloquent\OracleEloquent as Eloquent; class Post extends Eloquent{ // Define which fields are binary/BLOB types protected $binaries = ['content']; // Define the sequence name for auto-incrementing // Defaults to {table}_{primaryKey}_seq if not set protected $sequence = null;}
Working with BLOB Fields
OracleEloquent simplifies BLOB handling by allowing you to set binary fields directly:
use App\Models\Post;use Illuminate\Support\Str;use Illuminate\Http\Request; Route::post('save-post', function (Request $request) { $post = new Post(); $post->title = $request->input('title'); $post->company_id = auth()->user()->company->id; $post->slug = Str::slug($request->input('title')); $post->content = $request->input('content'); // Set BLOB field directly $post->save(); return redirect()->route('posts.show', $post->id);});
Custom Sequence Configuration
By default, OracleEloquent looks for a sequence named {table}_{primaryKey}_seq. If your sequence has a different name, configure it explicitly:
<?php namespace App\Models; use Yajra\Oci8\Eloquent\OracleEloquent as Eloquent; class Article extends Eloquent{ // Use a custom sequence name protected $sequence = 'article_id_seq';}
Now when you save a new Article:
$article = new Article();$article->title = 'My Article';$article->save(); echo $article->id; // Auto-populated from sequence
Retrieving BLOB Data
When fetching records, BLOB fields are automatically loaded as values:
$post = Post::find(1); echo $post->content; // Returns the actual content, not a LOB object
Limitations
Warning: Bulk insert operations with BLOB fields are not yet supported.
// This will NOT work with BLOB fields:Post::insert($postsArray);
For bulk operations, use individual save() calls instead.
Complete Example: Blog Post Model
<?php namespace App\Models; use Yajra\Oci8\Eloquent\OracleEloquent as Eloquent; class Post extends Eloquent{ protected $table = 'blog_posts'; protected $fillable = [ 'title', 'slug', 'content', 'company_id', ]; protected $binaries = [ 'content', ]; protected $sequence = 'blog_posts_id_seq'; public function company() { return $this->belongsTo(Company::class); }}
See Also
- Oracle BLOB Support - Detailed BLOB handling guide
- Oracle Sequence - Working with sequences
- Auto-Increment Support - Auto-incrementing primary keys