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

mardi 23 octobre 2018

Laravel Assets Point to Localhost/public instead of localhost/project/public

I recently used git to clone a Laravel 5.1 project from a repository to my local environment. I am using XAMPP, so I placed the project under C:/xampp/htdocs and can access it from localhost/project/public.

I updated the APP_URL variable in the.env file to point to "http://localhost/project".

I also updated the url value in config/app.php to:

'url' => env('APP_URL', 'http://localhost/project')

Right now, the both scripts resolve as http://localhost/public/assets/js/test.js:

I removed "/public" (also "public", just tetsing things) and replaced with so that now the call looks like the following and the script resolved just fine:

<script src="/assets/js/test.js"></script>

However, elixir is also being used:

<script src="."></script>

The page is not loading correctly; an Ajax call that errors out because the URL is is trying to reach is localhost/public/someotherfolder/details?=12345).

The above script seems to be the source of that AJAX call; if I comment it out, then the call doesn't run.

I checked the rev-manifest.json and it specifies "js/app.js". If I try to changed the script call to I get a 404 error. If I try add the path in the elixir call, I get a "file is not defined in manifest". Changing the manifest to use the whole path seems to defeat the purpose.

How can I solve this issue? It seems like I am missing an important step to let my application resolve without using the full path?



via Chebli Mohamed

get tasks where all task tags is in path tags

My code returns tasks where one of Task Tags name ->(tasktags) is in Path Tags->$TagArray .

I want to get Tasks where all Task Tags (tasktags) are in Path Tags array ->$TagArray.

$posts4 = Path::with(['pathtags' => function ($q) use ($TagArray) {
    $q->with(['Tasks'=>function($q) use ($TagArray) { 
        $q->has('tasktags', '=' , 2)->whereHas('tasktags', function ($query) use 
            ($TagArray) {
            $query->whereIn('name',$TagArray);

        })->with('tasktags');
    }]);
}])->first()



via Chebli Mohamed

dimanche 21 octobre 2018

Parsing html, grabbing nodeValue problem with DOMdocument

Trying to parse html page, but having some trouble at grabbing nodeValue's of dt and dd tags.

$outlineUrl = "http://www.sumitomo-rd-mansion.jp/kansai/higashi_umeda/detail.cgi";
foreach ($outlineUrl as $results) {
       $html = file_get_contents($results);
       $DOMParser = new \DOMDocument();
       $DOMParser->loadHTML($html)           

   foreach ($DOMParser->getElementsByTagName('dl') as $tr) {
             $property = trim($tr->getElementsByTagName('dt')[0]->nodeValue);
             $value = trim($tr->getElementsByTagName('dd')[0]->nodeValue);
   }

with this I can't grab the dl's and dt's nodeValue. Is my foreach loops wrong or something? Thanks for helping me out!



via Chebli Mohamed