Custom eloquent's table()->insert() functionstartsWith() and endsWith() functions in PHPHow to 'insert if not exists' in MySQL?Why shouldn't I use mysql_* functions in PHP?Laravel/Ardent - on save(), error: Relationship method must return an object of type IlluminateAdditional data members in Eloquent Collection not being copiedSlim 3 Eloquent initialization errorUsing PHP to insert into SQL Table with Foreign KeysLaravel Eloquent PHP how to get all rows in MySQL table with unique column values as keysThe sum amount from join tables is incorrectinsert multiple rows using join in a table

How do you send money when you're not sure it's not a scam?

Do higher dimensions have axes?

How much solution to fill Paterson Universal Tank when developing film?

Why don't humans perceive sound waves as twice the frequency they are?

Don't individual signal sources affect each other when using a summing amplifier?

Which modern firearm should a time traveler bring to be easily reproducible for a historic civilization?

How did Jayne know when to shoot?

Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?

Real orthogonal and sign

Company looks for long-term employees, but I know I won't be interested in staying long

/bin/sh: 0: Can't open sh

How do you name this compound using IUPAC system (including steps)?

Why are there few or no black super GMs?

Who determines when road center lines are solid or dashed?

Difference between class and struct in with regards to padding and inheritance

Why do jet engines sound louder on the ground than inside the aircraft?

Who or what determines if a curse is valid or not?

Why do space operations use "nominal" to mean "working correctly"?

Demographic consequences of closed loop reincarnation

Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation

Why does a tetrahedral molecule like methane have a dipole moment of zero?

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?

How to tell if JDK is available from within running JVM?

Do medium format lenses have a crop factor?



Custom eloquent's table()->insert() function


startsWith() and endsWith() functions in PHPHow to 'insert if not exists' in MySQL?Why shouldn't I use mysql_* functions in PHP?Laravel/Ardent - on save(), error: Relationship method must return an object of type IlluminateAdditional data members in Eloquent Collection not being copiedSlim 3 Eloquent initialization errorUsing PHP to insert into SQL Table with Foreign KeysLaravel Eloquent PHP how to get all rows in MySQL table with unique column values as keysThe sum amount from join tables is incorrectinsert multiple rows using join in a table






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to modify eloquent's basic functionnality of Manager::table('table')->insert($array) (and Manager::table('table')->update($array)) but I'm not sure how.



I've got a class that extends of the manager :



class Database extends IlluminateDatabaseCapsuleManager


Inside that class I created a function that extends of table() but I'm not sure how to make it extend of it's insert and update because the table() function returns an IlluminateDatabaseQueryBuilder and that builder in question is totally separate of the Manager.



Any idea how can I achieve this?



The end goal is having my own modified version of the insert so when I do this Manager::table('table')->insert($array), the insert would do something like the following and not the original insert :



public function insert(array $values)

if (empty($values))
return true;


if (! is_array(reset($values)))
$values = [$values];
else
foreach ($values as $key => $value)
ksort($value);

($value == NULL) ? $values[$key] = '' : $values[$key] = $value;



return $this->connection->insert(
$this->grammar->compileInsert($this, $values),
$this->cleanBindings(Arr::flatten($values, 1))
);



(Note that the code above is the copy/paste version of the actual function modified by my needs, so it's normal stuff like Arr::flatten would cause problems if I just copy/paste the function somewhere. So I'm trying to find an official way to EXTEND that said function so I wouldn't have to worry about such problems)










share|improve this question
























  • what is the purpose of adding such a function to eloquent lib ?

    – Sameera
    Mar 26 at 10:45











  • @Sameera the purpose is to have full control over what's being sent to the database. For example, in this case, it's to see if the values added are equal to NULL, if they are then replace them with empty strings. This is just an example to show that I need to have full control over the data that is being sent to the database. Also I'm not looking to add a function, I'm looking to extend the existing one and modify it.

    – Equgonyka
    Mar 26 at 10:47












  • @Equgonkya I think instead of extending manager, you can extend Illuminate/Database/Query/Builder and override insert function as your need.

    – Sameera
    Mar 26 at 11:09


















1















I'm trying to modify eloquent's basic functionnality of Manager::table('table')->insert($array) (and Manager::table('table')->update($array)) but I'm not sure how.



I've got a class that extends of the manager :



class Database extends IlluminateDatabaseCapsuleManager


Inside that class I created a function that extends of table() but I'm not sure how to make it extend of it's insert and update because the table() function returns an IlluminateDatabaseQueryBuilder and that builder in question is totally separate of the Manager.



Any idea how can I achieve this?



The end goal is having my own modified version of the insert so when I do this Manager::table('table')->insert($array), the insert would do something like the following and not the original insert :



public function insert(array $values)

if (empty($values))
return true;


if (! is_array(reset($values)))
$values = [$values];
else
foreach ($values as $key => $value)
ksort($value);

($value == NULL) ? $values[$key] = '' : $values[$key] = $value;



return $this->connection->insert(
$this->grammar->compileInsert($this, $values),
$this->cleanBindings(Arr::flatten($values, 1))
);



(Note that the code above is the copy/paste version of the actual function modified by my needs, so it's normal stuff like Arr::flatten would cause problems if I just copy/paste the function somewhere. So I'm trying to find an official way to EXTEND that said function so I wouldn't have to worry about such problems)










share|improve this question
























  • what is the purpose of adding such a function to eloquent lib ?

    – Sameera
    Mar 26 at 10:45











  • @Sameera the purpose is to have full control over what's being sent to the database. For example, in this case, it's to see if the values added are equal to NULL, if they are then replace them with empty strings. This is just an example to show that I need to have full control over the data that is being sent to the database. Also I'm not looking to add a function, I'm looking to extend the existing one and modify it.

    – Equgonyka
    Mar 26 at 10:47












  • @Equgonkya I think instead of extending manager, you can extend Illuminate/Database/Query/Builder and override insert function as your need.

    – Sameera
    Mar 26 at 11:09














1












1








1








I'm trying to modify eloquent's basic functionnality of Manager::table('table')->insert($array) (and Manager::table('table')->update($array)) but I'm not sure how.



I've got a class that extends of the manager :



class Database extends IlluminateDatabaseCapsuleManager


Inside that class I created a function that extends of table() but I'm not sure how to make it extend of it's insert and update because the table() function returns an IlluminateDatabaseQueryBuilder and that builder in question is totally separate of the Manager.



Any idea how can I achieve this?



The end goal is having my own modified version of the insert so when I do this Manager::table('table')->insert($array), the insert would do something like the following and not the original insert :



public function insert(array $values)

if (empty($values))
return true;


if (! is_array(reset($values)))
$values = [$values];
else
foreach ($values as $key => $value)
ksort($value);

($value == NULL) ? $values[$key] = '' : $values[$key] = $value;



return $this->connection->insert(
$this->grammar->compileInsert($this, $values),
$this->cleanBindings(Arr::flatten($values, 1))
);



(Note that the code above is the copy/paste version of the actual function modified by my needs, so it's normal stuff like Arr::flatten would cause problems if I just copy/paste the function somewhere. So I'm trying to find an official way to EXTEND that said function so I wouldn't have to worry about such problems)










share|improve this question
















I'm trying to modify eloquent's basic functionnality of Manager::table('table')->insert($array) (and Manager::table('table')->update($array)) but I'm not sure how.



I've got a class that extends of the manager :



class Database extends IlluminateDatabaseCapsuleManager


Inside that class I created a function that extends of table() but I'm not sure how to make it extend of it's insert and update because the table() function returns an IlluminateDatabaseQueryBuilder and that builder in question is totally separate of the Manager.



Any idea how can I achieve this?



The end goal is having my own modified version of the insert so when I do this Manager::table('table')->insert($array), the insert would do something like the following and not the original insert :



public function insert(array $values)

if (empty($values))
return true;


if (! is_array(reset($values)))
$values = [$values];
else
foreach ($values as $key => $value)
ksort($value);

($value == NULL) ? $values[$key] = '' : $values[$key] = $value;



return $this->connection->insert(
$this->grammar->compileInsert($this, $values),
$this->cleanBindings(Arr::flatten($values, 1))
);



(Note that the code above is the copy/paste version of the actual function modified by my needs, so it's normal stuff like Arr::flatten would cause problems if I just copy/paste the function somewhere. So I'm trying to find an official way to EXTEND that said function so I wouldn't have to worry about such problems)







php eloquent






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 11:00







Equgonyka

















asked Mar 26 at 10:38









EqugonykaEqugonyka

399 bronze badges




399 bronze badges












  • what is the purpose of adding such a function to eloquent lib ?

    – Sameera
    Mar 26 at 10:45











  • @Sameera the purpose is to have full control over what's being sent to the database. For example, in this case, it's to see if the values added are equal to NULL, if they are then replace them with empty strings. This is just an example to show that I need to have full control over the data that is being sent to the database. Also I'm not looking to add a function, I'm looking to extend the existing one and modify it.

    – Equgonyka
    Mar 26 at 10:47












  • @Equgonkya I think instead of extending manager, you can extend Illuminate/Database/Query/Builder and override insert function as your need.

    – Sameera
    Mar 26 at 11:09


















  • what is the purpose of adding such a function to eloquent lib ?

    – Sameera
    Mar 26 at 10:45











  • @Sameera the purpose is to have full control over what's being sent to the database. For example, in this case, it's to see if the values added are equal to NULL, if they are then replace them with empty strings. This is just an example to show that I need to have full control over the data that is being sent to the database. Also I'm not looking to add a function, I'm looking to extend the existing one and modify it.

    – Equgonyka
    Mar 26 at 10:47












  • @Equgonkya I think instead of extending manager, you can extend Illuminate/Database/Query/Builder and override insert function as your need.

    – Sameera
    Mar 26 at 11:09

















what is the purpose of adding such a function to eloquent lib ?

– Sameera
Mar 26 at 10:45





what is the purpose of adding such a function to eloquent lib ?

– Sameera
Mar 26 at 10:45













@Sameera the purpose is to have full control over what's being sent to the database. For example, in this case, it's to see if the values added are equal to NULL, if they are then replace them with empty strings. This is just an example to show that I need to have full control over the data that is being sent to the database. Also I'm not looking to add a function, I'm looking to extend the existing one and modify it.

– Equgonyka
Mar 26 at 10:47






@Sameera the purpose is to have full control over what's being sent to the database. For example, in this case, it's to see if the values added are equal to NULL, if they are then replace them with empty strings. This is just an example to show that I need to have full control over the data that is being sent to the database. Also I'm not looking to add a function, I'm looking to extend the existing one and modify it.

– Equgonyka
Mar 26 at 10:47














@Equgonkya I think instead of extending manager, you can extend Illuminate/Database/Query/Builder and override insert function as your need.

– Sameera
Mar 26 at 11:09






@Equgonkya I think instead of extending manager, you can extend Illuminate/Database/Query/Builder and override insert function as your need.

– Sameera
Mar 26 at 11:09













0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355083%2fcustom-eloquents-table-insert-function%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355083%2fcustom-eloquents-table-insert-function%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현