lundi 28 février 2022

How to configure web app to accept incoming emails?

I have 8 Lorex cameras, model number (N881A6), and it send out emails when motion detected. This is an example of camera number 7.

Alarm: Motion Detect 
Alarm input channel No.: 7  
Alarm device name: N881A6

enter image description here

Note : Subject line always show as ALERT

Since I don't have control over the subject line. I want to configure my Lorex to email to my owned site/server which is running on latest Ubuntu and running a Laravel App. I can accept incoming email from Lorex, parse for channel No.: 7 and create new email accordingly to trigger@applet.ifttt.com with custom subject line.

Ex. Subject : #lorex-action1 for camera 1 alexa routine

Is there away configure any web server to intercept email, parse it and create a new email ?



via Chebli Mohamed

LARAVEL : Passing an id through a form to a foreign key

I'm a beginner with Laravel and I'm a little bit confused with something.So what I'm trying to do is creating a familly through a form , then save this familly and after that we are redirect to a minorstudent form where you can create a student that is link to the familly you just created before.Everything on my models, migrations is okay because in my controller I can see the student and the familly.But my problems is when I create the familly I want to pass the 'id' of the table 'familly' to the table familly which has in its table the foreign key 'familly_id' ...But I dont know how to do it on my controllers.Thanks for the future help.

else {
          $minorstudent = new Minorstudent;
          $minorstudent->first_name = $request->first_name;
          $minorstudent->last_name = $request->last_name;
          $minorstudent->phone_number = $request->phone_number;
          $minorstudent->street_address = $request->street_address;
          $minorstudent->postal_code = $request->postal_code;
          $minorstudent->city = $request->city;
          $minorstudent->email_address = $request->email_address;
          $minorstudent->level = $request->level;
          if ($request->school!="none") {
              $minorstudent->school()->associate($request->school);
          }
          $minorstudent->save();
          return redirect('/familly');
        }

And I want the 'id' of the familly i created before being pass to the minorstudent into 'familly_id' wich is a foreign key.

 else {
        $minorstudent = Minorstudent::where('id',$request->id)->first();
        if ( $request->get('add_student_next') !== null ) {
          $familly = new Familly;
          $familly->first_name = $request->first_name;
          $familly->last_name = $request->last_name;
          $familly->phone_number = $request->phone_number;
          $familly->street_address = $request->street_address;
          $familly->postal_code = $request->postal_code;
          $familly->city = $request->city;
          $familly->email_address = $request->email_address;
          $familly->absence = 1;
          $familly->rules = 1;
          $minorstudent->familly_id()->attach($familly); 
          $familly->save();
          return redirect("/familly/id/student/new");
        }
        

This the familly controllers (form) where you create the familly and after that you are redirect to the minorstudent form

ps:Dont worry about the else at the beginning



via Chebli Mohamed

dimanche 27 février 2022

Laravel Two request value get decrement and insert in column

I'm New in Laravel I controller trying to get decrement (subtract) two input request value and pass result in ( balance_amount ) column.

example

input price request       100
input paid_amount request  50
result balance_amount      50

my Controller

 public function pay(Request $request)
    {
$request['price'] = $request->price;  
$request['paid_amount'] = $request->paid_amount;
$request['balance_amount'] = $request->balance_amount; 
 
    Installment::create($request);   
           }              

  return redirect( )->with('success',' PAID SUCCESSFULLY');

    }  


via Chebli Mohamed

Laravel 5.8: Uniqueness validation multiple columns with nested array wildcard (*.)

How to validate the uniqueness of combined column value in the nested array?

The input data is

$request = [
    [id, vol, number], 
    [id2, vol2, number2], 
    ...
];

The combination of vol and number must be unique with the data in magazines table.

id | vol | number
------------------
0  | 001 | 0001
1  | 001 | 0002
2  | 002 | 0001

Here's what my code looks like for now.

$validatedRequest = $request->validate([
            '*.id' => ['required', 'string'],
            '*.vol' => ['required', 'string'],
            '*.number' => ['required', 'string'], //need to add some rule here, I guess
        ]);

I've read the docs about how to validate nested array data with Rule::forEach() and also read the tutorial on how to validate the uniqueness on multiple column. However, I still cannot figure the way to access the *.vol data when creating rule for number.



via Chebli Mohamed

Copying .zip file failed because: filesize(): stat failed for /home/golden/test-pms.goldenholidaysbd.com/storage/laravel-backups/temp//2022

I cant backup the img file of public folder by spatie(v-3) and laravel (v-5.5). This is showing error. But this is working properly in locally.

This is the cpanel terminal error



via Chebli Mohamed

vendredi 25 février 2022

Laravel5.5-How to use morph to query different fields of different tables according to type

In Laravel 5.5,I have three tables.

posts
id - integer
name - string

users
id - integer
nickname - string

images
id - integer
url - string
imageable_id - integer
imageable_type - string

Then we add the morphTo association to the images model.

public function imageable()
{
    return $this->morphTo();
}

Problem:

Images::with(['imageable:id,name'])->get();

A problem found in the above use process is that when we design the table, the fields in posts and users are different, then there will be a requirement to judge in with whether the source of the table is posts or users to query different The table fields have the desired effect.

Similar to whereHasMorph:

Images::whereHasMorph(
    'imageable',
    [Users::class, Posts::class],
    function (Builder $query, $type) {
        if ($type === Users::class) {
            $query->selectRaw("id,nickname");
        } elseif ($type === Posts::class) {
            $query->selectRaw("id,name");
        }
    }
);

At present, no effective way has been found to achieve this purpose. The only one that can be achieved is as follows.

$imageUsers = images::with([
    'imageable' => function ($query) {
        $query->selectRaw("id,nickname");
    }
])->where('imageable_type', 'App\Users')->get();

$imagePosts = images::with([
    'imageable' => function ($query) {
        $query->selectRaw("id,name");
    }
])->where('imageable_type', 'App\Posts')->get();

So, My question is how to determine whether the source of the table is posts or users in with to query different table fields to achieve the desired effect.



via Chebli Mohamed

Passport package not reflecting on Laravel after installation

After I have installed the passport package in Laravel enter image description here

Why is the Passport package not reflecting in my Laravel code. I'm using Laravel Framework 8.79.0 version enter image description here



via Chebli Mohamed