mardi 27 novembre 2018

Truncate a table base on database connection in Laravel 5

I have a database connection nuc I have a table name Alerts

I'm trying to truncate that table by doing this

DB::connection('nuc')->statement('TRUNCATE Alerts');

I kept getting

enter image description here

QueryException in Connection.php line 629: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "alerts" does not exist (SQL: TRUNCATE Alerts)

How do I force truncate a table base on database connection?



via Chebli Mohamed

lundi 26 novembre 2018

How do I prevent other users from high jacking the HTTP request payload as other users?

I have

a laravel app with the route

Route::put('/api/{deviceMac}/access/update','DeviceController@update');

rule

If user A have deviceMac 000000000000, should only be making a PUT to

http://www.app.com/api/000000000000/access/update
{deviceMac:000000000000, access: true}

If user B have deviceMac 111111111111, should only be making a PUT to

http://www.app.com/api/111111111111/access/update
{deviceMac:111111111111, access: true}

User A should not be able hijacking the route update of other users

hijacking

User A should have access to 000000000000 only,

Right now, User A can tweak the HTTP request and make a PUT as User B

http://www.app.com/api/111111111111/access/update
{deviceMac:111111111111, access: false}


Questions

How do I prevent other users from high jacking the request payload as other users ?

Should I adjust my middleware to take care of this issue ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed

samedi 24 novembre 2018

Laravel: is it possible to do orWhere(Model::find())?

I am using Lumen Laravel 5.1. I have a many to many relation between task and user, and pivot table called task_user, I recently asked this question, inspired by the answer and by reading the documentation, I think I can do this

$users = User::tasks()
        ->where('domain_id', $domainId)
        ->where('created_by', $userId)
        ->orWhere(User::tasks()->find($userId))
        ->Where(function ($query) {
            $query->where("is_done", 0)
                ->orderBy('due_date', 'DESC');
        })
        ->Where(function ($query) {
            $query->Where("is_done", 1)
                ->Where("closed_dated", Carbon::today())
                ->orderBy('closed_date', 'ASC');
        })
        ->get();

Before I accept his answer I have two questions:

1- A user can have his id related to a task, in 2 places

  • task_user table if is an assignee
  • created_by in tasks table, if he created it

So I want to know if he's an assignee or if he created it, both cases I want to display his tasks. Found nothing on google, so can I do this?

where(....) -> orwhere(model::find())

  1. My second question is: Should I use ->pivot->id to get to task, instead of find()? The docs about ->pivot are confusing and the tutorials I read don't use it. I don't know if it helps me.


via Chebli Mohamed

mardi 20 novembre 2018

vendredi 16 novembre 2018

auth()->user()->id is not working when I use it in controller using routes to api.php

public function store(Request $request)
    {
        $booking = ($request->isMethod('put')) ? Booking::findOrFail($request->booking_id) : new Booking;
        $booking->checkIn = $request->checkIn;
        $booking->checkOut = $request->checkOut;
        $booking->room_id = $request->room_id;
        $booking->user_id = auth()->user()->id;//not working

        if($booking->save()){
            return new BookingResource($booking);
        }
    }

Route::put('/booking','BookingsController@store');//api.php

Here auth()->user()->id is not working but its working find if i use it the same code but route code in routes/web.php



via Chebli Mohamed

jeudi 15 novembre 2018

Can't modify 'updated_at' in my database after adding a column with a migration in Laravel 5.1

I am trying to add a new integer "id" column in a table of my database to map every row with an id. In order to do so, I am using a migration in Laravel 5.1. The run() function of the migration is exactly the following:

public function up()
{
    Schema::table('license_keys', function($table) {
        $table->integer('id_nuevo');
    });
}

The table I am trying to modify is set with default 'updated_at' and 'created_at' timestamps.

I execute the migration and the column is added correctly. I made sure to add the new column in the $fillable variable in my model. The next step in the process is to set the ids correctly, because that column is created with all 0s. In order to do so, I am using a Seeder with the following code:

public function run()
{
    $i=1;
    $licenses = LicenseKey::getEveryLicenseKey();
    foreach ($licenses as $license){
        $license->id_nuevo = $i;
        //$license->timestamps = false;
        $license->save();
        $i++;
    }

}

But the problem starts here. When I try to update any field of any row with the save() function it gives me the following error:

[Illuminate\Database\QueryException]                                                                                                                                                                     
 SQLSTATE[21S01]: Insert value list does not match column list: 1136       Column count doesn't match value count at row 1 (SQL: update `license_keys`   set `id_nuevo` = 1, `updated_at` = 2018-11-15 13:24:11   
 where `hash_key` = 0...0b)                                                                                                                                                     



  [PDOException]                                                                                                       
  SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1

But if I set the timestamps to false (commented line in the code), the operation succeeds. Even if I try to manually change the value of the 'updated_at' column in phpMyadmin, it gives me the same error. Can anybody help me with this problem?

Thanks



via Chebli Mohamed

dimanche 11 novembre 2018

The installation directory "/usr/local/bin" is not writable - How to fix this? I am trying to install the composer globally

ERROR message while trying to setup Composer

192:~ biancalouisedairo$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 192:~ biancalouisedairo$ php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" Installer verified 192:~ biancalouisedairo$ php composer-setup.php --install-dir=/usr/local/bin All settings correct for using Composer The installation directory "/usr/local/bin" is not writable 192:~ biancalouisedairo$



via Chebli Mohamed

jeudi 8 novembre 2018

Is there a portable PHP artisan tool?

At work, we are using PHP 5.6, Lumen 5.1. Due to some setup issues related to the project and work, I cannot run any composer command nor PHP artisan, I get errors like this and others. The project only runs on the server. Now if I want to create a table, I have two options:

  • Run the migration on the server, then download it using sftp
  • Create another lumen project on my PC, do migration and then move them to the project's folder

Is there a portable php artisan I can put in the project folder or can I alias php artisan from some other lumen project to generate files in the project I work on?



via Chebli Mohamed

mercredi 7 novembre 2018

How can I change "127.0.0.1:8000" to my desired url. (laravel)

I'm using laravel and I don't know how to customize the default url which is "127.0.0.1:8000" or "localhost:8000" to my desired url.

My expectation is to change 127.0.0.1:8000 to sample.dev when I do php artisan serve

Do I really need to move my projects to htdocs or www?

Please help...



via Chebli Mohamed

mardi 6 novembre 2018

NPM installation problem In Laravel in Windows 10

My NPM ver is 5.6.0 My Node ver is v8.11.3 Laravel Framework 5.7.12

I have some Problems When i want to install The npm in laravel which are as follows

npm install

npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.

npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.

node-sass@4.10.0 install C:\xampp\htdocs\Newapp\node_modules\node-sass

node scripts/install.js

'node' is not recognized as an internal or external command, operable program or batch file.

npm WARN img-loader@3.0.1 requires a peer of imagemin@^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):

npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! node-sass@4.10.0 install: node scripts/install.js

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the node-sass@4.10.0 install script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

npm ERR! C:\Users\bamas\AppData\Roaming\npm-cache_logs\2018-11-07T03_33_04_531Z-debug.log

MY package.json is

{ "private": true, "scripts": { "dev": "npm run development", "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch": "npm run development -- --watch", "watch-poll": "npm run watch -- --watch-poll", "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", "prod": "npm run production", "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" }, "devDependencies": { "axios": "^0.18", "bootstrap": "^4.0.0", "cross-env": "^5.1", "jquery": "^3.2", "laravel-mix": "^2.0", "lodash": "^4.17.5", "popper.js": "^1.12", "vue": "^2.5.17" } }

I already tried everithing like cache clear re installing nodemodules but its not effect.. My NPM is alright Because whenever i run my other Nodejs script it work perfectly i am using gitbash....



via Chebli Mohamed

none Database Model two attributes in Laravel

i'm a newbie in Laravel Please Guide me.

1- Port is a Model and Coordinates is a none database Model. 2- 2 floats are lat and long in Port Model.

When a port is loaded from the database, the 2 floats are casted to a Coordinates-object. Second Question How to make a non-database model with two attributes.



via Chebli Mohamed

lundi 5 novembre 2018

Using multiple controllers in the same route gets route undefined

I get an error of undefined route when using multiple controllers in the same route:

Here is the code my controllers:

public function triealphabet(){
    $list_grocery = miscellaneous::all();
    $list_grocery = $list_grocery->sortBy('name');
    return view('markets.miscellaneous')->with('list_grocery',$list_grocery);}
public function triecreation(){
    $list_grocery = miscellaneous::all();
    $list_grocery = $list_grocery->sortBy('created_at');
    return view('markets.miscellaneous')->with('list_grocery',$list_grocery);}

and here are my routes code :

Route::get('/miscellaneous','groceryController@listGrocery')->name('groceriesmarket'); 
Route::get('/miscellaneous','groceryController@triealphabet')->name('triealphabet');
Route::get('/miscellaneous','groceryController@triecreation')->name('triecreation');

P.S: If I use an other route path like '/miscellanous-tri-alphabet' I don't get any other errors, but other than that I get an error of undefined route



via Chebli Mohamed

vendredi 2 novembre 2018

Can any one filter admin theme and give rank to the themes to use in laravel?

I am so confused to choose admin theme for laravel can anyone list me best admin panel as per its quality, and give description for what, that is flexible?



via Chebli Mohamed

kendo directive for anuglarjs how to update record with id and go to update page?

I have taken the id from selected field in kendo grid, and I am using angularjs directive. Now I don't understand how to update the selected Id record. I mean to say with the selected Id I want to go to update page. The work I have done is given below.

 (function () {
angular.module('moduleName').directive('kendoGridRowDblClick', kendoGridRowDblClick);

function kendoGridRowDblClick() {
    return {
        link: function (scope, element, attrs) {
            scope.$on("kendoWidgetCreated", function (event, widget) {

                if (widget !== element.getKendoGrid())
                    return;

                attachDblClickToRows(scope, element, attrs);

                //element.data("kendoGrid").bind('dataBound', function () {
                  //  attachDblClickToRows(scope, element, attrs);
                //});
            });
        }
    };

    function attachDblClickToRows(scope, element, attrs) {
         var id = $(element).find(".k-state-selected td:eq(1) span").html();
     console.log($(element).find(".k-state-selected td:eq(0) span").html());   
    }
})();

With td:eq(1) it gives me the correct id when I dblclick on a record in a grid, With console.log it gives me the span value which is given below, and i want to take the id and go to the new state for updating page. I have defined the span here which is hidden field

{field: "", hidden: true, template: "<span>Akhtar</span>"},

And ofcourse I have database fields too, but here I just want to go to an update state/page instead of just printing the span value Akhtar in console. Any help would be appreciated. Thanks in advanced



via Chebli Mohamed

jeudi 1 novembre 2018

Laravel package musonza/groups Laravel 5 user groups package how to start after running migrations?

I have been able to finish up but the migrations part but i don't know how to start I'm new to laravel and i want to use this package in a project i'm building. Any tutorials, guidance or recommendations is much appreciated.



via Chebli Mohamed