The function you are looking for is within the class Builder (vendor/framework/src/Illuminate/Database/Query/Builder/Builder.php), it is difficult to find anything beyond the definitions of the documentation, if you want to break up each function of the framework you will have to search in the files, which are fortunately commented.
Builder.php class Insert function. (Laravel version 5.5)
/**
* Insert a new record into the database.
*
* @param array $values
* @return bool
*/
public function insert(array $values)
{
// Since every insert gets treated like a batch insert, we will make sure the
// bindings are structured in a way that is convenient when building these
// inserts statements by verifying these elements are actually an array.
if (empty($values)) {
return true;
}
if (! is_array(reset($values))) {
$values = [$values];
}
// Here, we will sort the insert keys for every record so that each insert is
// in the same order for the record. We need to make sure this is the case
// so there are not any errors or problems when inserting these records.
else {
foreach ($values as $key => $value) {
ksort($value);
$values[$key] = $value;
}
}
// Finally, we will run this query against the database connection and return
// the results. We will need to also flatten these bindings before running
// the query so they are all in one huge, flattened array for execution.
return $this->connection->insert(
$this->grammar->compileInsert($this, $values),
$this->cleanBindings(Arr::flatten($values, 1))
);
}
The class
Categoria
has something likeextends Model
, right?– Jéf Bueno
Yes, this class has a extends Model.
– Igor Henrique
The method can be in this class =)
– Jéf Bueno
there’s no way in this place with that name.
– Igor Henrique
https://laravel.com/api/5.5/Illuminate/Database/Query/Builder.html#method_insert
– Marcelo