mercredi 31 octobre 2018

NotFoundHttpException error on post method Laravel 5.1

I got error NotFoundHttpException below

Error

Here is my route

Route::post('/ticket/{slug?}/edit', 'TicketsController@update');

My function update on TicketController

public function update($slug, TicketFormRequest $request)
{
    $ticket = Ticket::whereSlug($slug)->firstOrFail();
    $ticket->title = $request->get('title');
    $ticket->content = $request->get('content');
    if($request->get('status') != null) {
        $ticket->status = 0; } else {
    $ticket->status = 1;
}
$ticket->save();
return redirect(action('TicketsController@edit', $ticket->slug))->with('status', 'The ticket '.$slug.' has been updated!');

}

My function edit

 public function edit($slug)
{
    $ticket = Ticket::whereSlug($slug)->firstOrFail();
    return view('tickets.edit', compact('ticket'));
}

Am I missed something? I think my routes was right, maybe my update function is wrong



via Chebli Mohamed

lundi 29 octobre 2018

Query Builder Eloquent Where clause for TimeStamp - Laravel 5.1

I have a table and search bar.

enter image description here

When user input in the search that when I grab that and query my database.

This is what I got

public function getLogsFromDb($q = null) {

    if (Input::get('q') != '') {
        $q = Input::get('q');
    }
    $perPage = 25;

    if ($q != '') {

        $logs = DB::table('fortinet_logs')
            ->orWhere('account_id', 'like', '%'.$q.'%')
            ->orWhere('cpe_mac', 'like', '%'.$q.'%')
            ->orWhere('p_hns_id', 'like', '%'.$q.'%')
            ->orWhere('g_hns_id', 'like', '%'.$q.'%')
            ->orWhere('data', 'like', '%'.$q.'%')
            ->orWhere('created_at', 'like', '%'.$q.'%') <----🐞
            ->orderBy('updated_at', 'desc')->paginate($perPage) 
            ->setPath('');


            //dd($logs);

        $logs->appends(['q' => $q]);

    } else {

        $logs = DB::table('fortinet_logs')
            ->orderBy('created_at', 'desc')->paginate($perPage)
            ->setPath('');
    }

    return view('telenet.views.wizard.logTable', get_defined_vars());

}


Result

In the network tab, I kept getting

Undefined function: 7 ERROR: operator does not exist: timestamp without time zone ~~ unknown

enter image description here


Questions

How would one go about and debug this further ?


I'm open to any suggestions at this moment.

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



via Chebli Mohamed

samedi 27 octobre 2018

Laravel Model Factory Error: Trying to get property of non-object

I'm trying to use a model factory to seed my database, but when I run it I get the error:

Trying to get property 'id' of non-object

Here is my code:

// TasksTableSeeder.php

factory(pams\Task::class, '2000', rand(1, 30))->create();

// ModelFactory.php

$factory->defineAs(pams\Task::class, '2000', function (Faker\Generator $faker) {
static $task_number = 01;
return [
    'task_number' => $task_number++,
    'ata_code' => '52-00-00',
    'time_estimate' => $faker->randomFloat($nbMaxDecimals = 2, $min = 0.25, $max = 50),
    'work_order_id' => '2000',
    'description' => $faker->text($maxNbChars = 75),
    'action' => '',
    'duplicate' => '0',
    'certified_by' => '1',
    'certified_date' => '2015-11-08',
    'status' => '1',
    'created_by' => '1',
    'modified_by' => '1',
    'created_at' => Carbon\Carbon::now()->format('Y-m-d H:i:s'),
    'updated_at' => Carbon\Carbon::now()->format('Y-m-d H:i:s'),
    ];
});

I've tried removing all variables from the model factory and using constants, but that doesn't fix it. I've tried pulling the data from the ModelFactory.php and put it directly into the TasksTableSeeder.php and it does work, however I was using constants and no variables.

I cannot for the life of me figure out what 'id' it's talking about.

I'm running Laravel v5.1



via Chebli Mohamed

jeudi 25 octobre 2018

how to use this php sql on laravel??? (dynamic form field)

<?php
$fields = array(
 array(
 'meta_id' => 'name',
 'display_name' => 'Name'
 ),
 array(
 'meta_id' => 'address',
 'display_name' => 'Address'
 ),
 array(
 'meta_id' => 'cps_name',
 'display_name' => 'CSP Name'
 )
);


$tables = array();
$query_fields = array();
$joins = array();
$fcount = 1;


array_push($query_fields, "reports.*");

foreach ($fields as $key => $value) {
 $table_name = "tables" . $fcount++;
 array_push($query_fields, $table_name.".".$value['meta_id']." AS ".$value['display_name']);

 array_push($joins, "INNER JOIN reports_meta_values ".$table_name." ON reports.id = ".$table_name.".report_id AND ".$table_name.".meta_id='".$value['meta_id']."'");
}


$final_sql = "SELECT " .implode(",", $query_fields) . " FROM reports " . implode(" ", $joins). " WHERE 1";

echo "$final_sql";

?>



via Chebli Mohamed

Set up Laravel project to work with multiple Domain Name

enter image description here

I have successfully configured multiple domains to point to my Laravel 5.1 project

<Virtualhost *:80>
  VirtualDocumentRoot "/Users/Sites/project/public"
  ServerName app.com
  UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
  VirtualDocumentRoot "/Users/Sites/project/public"
  ServerName app2.com
  UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
  VirtualDocumentRoot "/Users/Sites/project/public"
  ServerName app3.com
  UseCanonicalName Off
</Virtualhost>

When I go to

app.com app2.com app3.com

any of them will point to my project and load the log-in screen.


Issue

When I login, regardless when I am from, I kept redirecting my users to

app.com/dashboard


Goal

My goal is, any request from

app.com  --> log-in --> redirect to --> app.com/dashobard
app2.com --> log-in --> redirect to --> app2.com/dashobard
app3.com --> log-in --> redirect to --> app3.com/dashobard


Questions

How would one go about and do this on a Laravel project ?

Is this something that I can do on the application layer or web server ?


I'm open to any suggestions at this moment.

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



via Chebli Mohamed

How to insert in a translatable field?

Using Lumen 5.1, I'd like to know how to to CRUD on a translatable field, in my case it's name.

This is migration file

class CreateDomainHolidays extends Migration
{

    protected $table = 'domain_holidays';
    protected $app_table = true;

    public function up()

    {
        Schema::create($this->getTable(), function (Blueprint $table) {
            $table->increments('id');

            $table->integer('domain_id')->unsigned()->nullable();
            $table->foreign('domain_id')->references('id')
                ->on(self::getTableName('domains'))->onDelete('cascade');
            $table->string('name')->nullable()->default('')->translatable = true;
            $table->dateTime('start_date');
            $table->dateTime('end_date');
            $table->tinyInteger('half_day_start')->default(0);
            $table->tinyInteger('half_day_end')->default(0);
            $this->parenttable = $table;

        });
        $this->createTableWithTranslation($this->parenttable);

    }

    public function down()
    {
        $this->dropTranslationTable($this->getTable());
        Schema::drop($this->getTable());
    }
}

This is my model

 class Holiday extends BaseModel
    {
        protected $table = 'domain_holidays';
        protected $app_table = true;
        public $timestamps = false;

        protected $translation = true;
        public function translations()
        {
            return $this->hasMany('App\Models\General\HolidayTranslations', 'parent_id');
        }

    }

    class HolidayTranslations extends BaseTranslationModel
    {
        protected $table = 'domain_holidays_i18n';
        protected $primaryKey = 'translation_id';
    }
}

domain_holidays contains

id
domain_id
start_date
end_date
half_day_start
half_day_end

domain_holidays_i18n contains

translation_id
parent_id
lang
name

Something like this is not working

public static function setHoliday($domainId, $name, $startDate, $endDate, $halfDayStart, $halfDayEnd)
{
    Holiday::unguard();
    return Holiday::create([
        'domain_id' => $domainId,
        'name' => $name,
        'start_date' => $startDate,
        'end_date' => $endDate,
        'half_day_start' => $halfDayStart,
        'half_day_end' => $halfDayEnd
    ]);
}

Postman would return an error

SQLSTATE[42S22]: Column not found: 1054 Unknown column &#039;name&#039; in &#039;field list&#039;



via Chebli Mohamed

mercredi 24 octobre 2018

Laravel Data change when i pass it from Controller To view

i have relations path has many tags and tags have many tasks and tasks have many tags so task may have one or more tag . My Controller return tasks that have 1 tag only and is working fine

public function task(){

 $Tasks= Path::with(['pathtags' => function ($q) {
  $q->with(['Tasks'=>function($q) {
  $q->has('tasktags', '=' , 1)
 ->with('tasktags'); }]); 
 }])->first();

  return $Tasks;
}

but When I return $Tasks in view I get all tasks in the database

i tried

  return view('task', ['Tasks' => $Tasks);
  return view('box',compact('Tasks'));

but still get all tasks not one that have 1 tag



via Chebli Mohamed