jeudi 27 avril 2017

How can I use wordnet with laravel?

How can I use wordnet with laravel? I have tried to use php wordnet api which is not working and outdated I assume. Can anyone provide me with some guideline. Thanks in advance!!



via Chebli Mohamed

query builder in model, laravel

I'm trying to do a query within a model, then call it in the url with

namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Collection;

class TeachingPoint extends Model
{
use SoftDeletes;

protected $with = ['testRelation'];

public function testRelation()
{
      $table = DB::table('test_table')->where(xxxx)->->get();
      foreach($table as $data)
      {
        etc...
      }
      return $data;
}

I need to do it on the model, is this possible? Or I have to do it with "attribute" or in the controller itself

Thank you



via Chebli Mohamed

Understand Laravel route with optional parameter

I'm trying to create a route with one optional parameter with Laravel 5.4.

Route :

Route::get('/run/{zone?}/id/{id}', 'RunController@show');

Controller :

class RunController extends Controller
{
    public function show()
    {
        $route = \Route::current();
        $zone = $route->parameter('zone') ?: 'default';
        $id = $route->parameter('id');

        Run::setZone($zone);
        $run = Run::findOrFail($id);
        return view('run.show')->with(['run' => $run]);
    }
}

The url run/test/id/42 works like expected.

But with run/id/42 I got a nice NotFoundHttpException in RouteCollection.php when I expect the same result than run/default/id/42

What did I missed ?



via Chebli Mohamed

Laravel 5.4, allow the user to only favourite something once so it does not get added to their list twice?

I have a working favourite system in my application, that allows the users' to favourite a charity and these favourites are displayed to them on another page.

The only problem is that the user is able to favourite the same charity multiple times, how could I limit this to just once and then maybe tell the user that they already have favourited this?



via Chebli Mohamed

Modifying the included auth controller for Laravel 5.3

I am using the basic login and registration scaffold that comes with Laravel 5.3. I've also created a logging function so that I can log some of the basic user actions for my platform, such as updating or deleting records.

I'd like to add the logging to the user login process so that I can log when they've logged in and a failed attempt. Because I'm using the basic included scaffolding, I'm not sure where to do this?



via Chebli Mohamed

Access query string parameters using Laravel 5

I'm trying to use an existing route within my application using Request::create(). However, when passing parameters into the method I am not able to get back the respective values, instead I am getting null whic results in me getting an empty array.

The controller method that I am trying to retrieve information from is:

public function grossReport(Request $request)
{
    $fromDate  = $request->route('fromDate');
    $toDate    = $request->route('toDate');

    $result    = LoanApplication::with('product')->with('user')->with('loanPayment')
                ->where('state', 'Active')
               ->whereBetween('created_at', [$fromDate, $toDate])->paginate(10);

    foreach ($result as $value) {
        $value->branch = (isset($value->user->branch_id)) ? Branch::find($value->user->branch_id) : '';

        $value->totalGrossBalance = $this->calculate->loanBlance($value->id);
    }


    return $result;
}

I'm trying to use the route retrieve information from the grossReport() above.

$res = Request::create('/reports/get-gross-report/2013-01-08-00-00-00/2017-04-27-23-59-59', 'GET', array(), array(), array(), $server);
$response = \Route::dispatch($res)->getContent();
return $response;

Can anyone explain to me what's causing this problem. Thanks in advance.



via Chebli Mohamed

Want to add Coloumn but Migration Class Not Found Even It exist

I am learning Laravel.

Here is my migration file code.

class CreatePostTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('post', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned(); // i want to add this column after adding this line i runs the command refresh but it shows below errors.
        $table->string('title');
        $table->text('body');
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('post');
}
}

Now i have a problem that Whenever i runs this command in terminal in PHP STORM

php artisan migrate:refresh

it shows following errors.

PHP Fatal error: Class 'AddIsAdminColumnToPostTable' not found in C:\xampp\htdocs\cms\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php on line 335

and following error also

Symfony\Component\Debug\Exception\FatalErrorException] Class 'AddIsAdminColumnToPostTable' not found

I tried composer dump-autoload in terminal solution from here but not working. I also used rollback command but still having issue.

How can make refresh this?



via Chebli Mohamed