samedi 3 août 2019

How to add new text on the exiting file using fopen php

i want to create a system that can add every text input to the exiting file but on specify location.

i have a file that named testing.php.

The contents of this file are like this

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::group(['prefix' => 'auth', 'middleware' => 'cors'], function ($router) {
    Route::post('login', 'Auth\AuthController@login');
    Route::post('logout', 'Auth\AuthController@logout');
});

Route::group(['middleware' => 'cors'], function(){
    Route::post('user/CreateUser', 'Admin\UserController@CreateUser');
});

and i want to add Route::get('user/RemoveUser', 'Admin\UserController@RemoveUser'); to the file and i want it added on cors middleware.

so the files will be like this

Route::group(['middleware' => 'cors'], function(){
    Route::post('user/CreateUser', 'Admin\UserController@CreateUser');
    Route::get('user/RemoveUser', 'Admin\UserController@RemoveUser');
});

how i can do that?

$file_name= 'test';
$write_text= "Route::get('user/RemoveUser', 'Admin\UserController@RemoveUser');";
$folder= "C:/xampp/htdocs/jazuly/tests/";
$ext= ".php";
$file_name= $folder."".$file_name."".$ext;
$edit_file = fopen($file_name, 'a');

fwrite($edit_file, $write_text);
fclose($edit_file);

i only know the basic of fopen usage, if theres any other ways i'll appreciated it, or maybe laravel have its own features?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire