1.1 You have Transaction model
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Transaction extends Model
{
//
}
2.1 You have TransactionController
<?php namespace App\Http\Controllers;
use App\Transaction;
class TransactionController extends Controller
{
public function get()
{
dd(Transaction::find(1));
}
}
3.1 Call Static
+ vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
/**
* Handle dynamic static method calls into the model.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
return (new static)->$method(...$parameters);
}
3.2 Call function don't exist
+ vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
/**
* Handle dynamic method calls into the model.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
if (in_array($method, ['increment', 'decrement'])) {
return $this->$method(...$parameters);
}
if ($resolver = (
static::$relationResolvers[get_class($this)][$method] ?? null))
{
return $resolver($this);
}
return $this->forwardCallTo(
$this->newQuery(), $method, $parameters);
}
3.3 $this->newQuery()
+ vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
/**
* Get a new query builder for the model's table.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function newQuery()
{
return $this->registerGlobalScopes(
$this->newQueryWithoutScopes()
);
}
3.4 $this->newQueryWithoutScopes()
+ vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
/**
* Get a new query builder that doesn't have any global scopes.
*
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function newQueryWithoutScopes()
{
return $this->newModelQuery()
->with($this->with)
->withCount($this->withCount);
}
3.5 $this->newModelQuery()
+ vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
/**
* Get a new query builder that doesn't have
* any global scopes or eager loading.
*
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function newModelQuery()
{
return $this->newEloquentBuilder(
$this->newBaseQueryBuilder()
)->setModel($this);
}
3.6 $this->newBaseQueryBuilder()
+ vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
/**
* Get a new query builder instance for the connection.
*
* @return \Illuminate\Database\Query\Builder
*/
protected function newBaseQueryBuilder()
{
return $this->getConnection()->query();
}
4.1 File
vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php
4.2 forwardCallTo
/**
* Forward a method call to the given object.
*
* @param mixed $object
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
protected function forwardCallTo($object, $method, $parameters)
{
try {
return $object->{$method}(...$parameters);
} catch (Error|BadMethodCallException $e) {
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
if (! preg_match($pattern, $e->getMessage(), $matches)) {
throw $e;
}
if ($matches['class'] != get_class($object) ||
$matches['method'] != $method) {
throw $e;
}
static::throwBadMethodCallException($method);
}
}
5.1 File
vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php
5.2 Call static
<?php namespace Illuminate\Database\Query;
class Builder
{
/**
* Execute a query for a single record by ID.
*
* @param int|string $id
* @param array $columns
* @return mixed|static
*/
public function find($id, $columns = ['*'])
{
return $this->where('id', '=', $id)->first($columns);
}
/**
* Set the table which the query is targeting.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $table
* @param string|null $as
* @return $this
*/
public function from($table, $as = null)
{
if ($this->isQueryable($table)) {
return $this->fromSub($table, $as);
}
$this->from = $as ? "{$table} as {$as}" : $table;
return $this;
}
and more ....
public function xyz()
{
....
}
}