lundi 28 novembre 2016

how can I update My values using Laravel 5.2

this is My addpermission function in My Controller, I need update function here to update values. how can I put update codes here. (I need update function in same addpermission function)

public function addPermission(Request $request, $id,  Permission $permission)
    {
         $this->validate($request, [
            'status'   => 'required'


        ]);

        $permission = new Permission;

        $permission->status = $request->input('status');
        $permission->project_id       = $id;
        $permission->collaborator_id =  $request->input('cid');
        $permission->save();
        return redirect()->back()->with('info','Permission has been added to your Collaborator successfully');
}



via Chebli Mohamed

Vue js and Laravel site development

I would like to know . our team thinking to have frontend and backend with two separate location. both frontend and backend will be connected through RESTful API. Is it a good practice ? suggestions are welcome.

Would like to know more advises. Thank you.



via Chebli Mohamed

Remote MySQL database connection Laravel 5 not working

I'm using laravel 5. i need to get some data from a remote MySQL database.

i've already set up my database connection in config/database.php. This is how it looks:

'connections' => [

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

    'remotemysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '************'),
        'database'  => env('DB_DATABASE', 'osys'),
        'username'  => env('DB_USERNAME', 'Syn'),
        'password'  => env('DB_PASSWORD', '****************'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],
],

The connection info is correct, i already tested it and i'm able to connect to the remote database.

To test it out i just fetched the database connection and the data in my controller to send it to a view to check whether or not everything is working alright. This is my controller:

...
use DB;
...

public function item()
{

    $items = DB::connection('remotemysql')
    ->table('ip_products')
    ->get();
    return view('admin.item', compact('items'));
}

and this is my view:

...
<tbody>     
 @foreach ($items as $item)
    <tr>
       <td></td>
    </tr>
 @endforeach
</tbody>
...

When i try to load my view i get this error message:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dvs.ip_products' >doesn't exist (SQL: select * from ip_products)

The error shows me that Laravel tries to get the table form the dvs database (wich is the main site database). So it isn't using the connection 'remotemysql'. If it couldn't connect to the remote database it would have got a connection error but i think its not using the remote connection at all.

What can i do to fix this issue ?



via Chebli Mohamed

How to implement subscription plan restrictions? (php)

Let's say we have a simple SAAS that offers two types of plans. For example, in the cheapest plan you can create 20 lists at maximum and in the next plan you can create up to 50 lists. This is just one feature of the pricing model. Assuming the pricing model is based on 4-5 different features for each plan, what would be a good practice to check and enforce those restrictions?

I guess, the (messy) way would be to add a bunch of 'ifs' in different points, eg: if $user->plan->limitReached, do this etc.

Maybe another approach would be to throw some kind of events on user actions and handle the checks in a more 'centralized' way? What are your thoughts on this scenario? Any suggestions would be appreciated. Thank you



via Chebli Mohamed

Laravel send mail to multiple recipients with their name

We can send mails to multiple recipients by passing the array of recipients in the $message->to() function of mail. Send Mail to Multiple Recipients

But how can I add the names of these recipients which are in array to the mail. For Example: When I send a mail to single recipient then its like where we can pass the second parameter as name of the recipient.

$message->to("alex_test@gmail.com", "Alex");

But when I send the mail to multiple recipients the its like:

$emails = ['email@esomething.com', 'email1@esomething.com','email2@esomething.com'];

Mail::send('emails.welcome', [], function($message) use ($emails)
{    
    $message->to($emails)->subject('This is test e-mail');    
});

Is there a way that I can add the names of the recipients to this.



via Chebli Mohamed

Populate Laravel form with Auth::user

I've used a form to save my user's requests in a database. Requests can be made without logging in, but also while logged in.

When someone is logged in, their info should be put into the form already, so they won't have to.

I wrote this in one of my form parts, to retreive their info, but it returns code:

<?php echo e(Auth::user()->organisation); ?>

The form is put like this:

{!! Form::Text('organisation', '}', array('required' => 'required')) !!}

I know it's probably something really small that i'm missing, but I can't put my finger on it



via Chebli Mohamed

How to change password reset link in Laravel5.3?

I made password reset with php artisan make:auth.

I know password reset link in the variable that called $actionUrl

That generate link like this.

http://ift.tt/2gyaaEU

What I wanna do is change link like this.

http://ift.tt/2frnZJ7

I think that link is composed by href + token. So I try to make custom link, but that is wrong work.

app/User.php -- change mail body from vendor view to own view

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\CustomPasswordReset;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new CustomPasswordReset($token));
    }
}

app/Notificantions/CustomPasswordReset.php -- show own view to email body

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class CustomPasswordReset extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)->view('admin.emails.password');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

resources/views/admin/emails/password.blade.php

<a href=""></a>

Where should I change?



via Chebli Mohamed