konrms

konrms

Member Since 5 Months Ago

Experience Points 2,420
Experience Level 1

2,580 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 9
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

04 Jun
1 week ago

konrms left a reply on Query To Select Data From Database Table And Array

@NASH - I understand the risk. But is it possible to be done with Raw query?

konrms started a new conversation Query To Select Data From Database Table And Array

How can I select data with raw query from data that exists both in database table and an array?

For example I want to store to $sc the result of the following query. The variable $cs is an array which has data from previous query execution.

$sc = DB::select(DB::Raw("select hrp1001_sc.rel_obj_id from hrp1001_sc, today_date where today_date.today <= hrp1001_st_cs.end_date and today_date.today >= hrp1001_st_cs.st_date and hrp1001_sc.object_id = $cs"));

31 May
2 weeks ago

konrms left a reply on Help With Csv File Uploading...

@DEVFREY - Hello again @!

I had some issues with my csv numbers and had to update ',' to '.' in numbers (eg 7,5 to 7.5). I think that can be fixed somehow...

But my basic issue is how to pass the file from the form to my controller. The user should enter some other data along with the csv. The csv is uploaded only if it is placed inside public folder and in fact code does not take in mind my (desktop located) file. The code as it is takes file from public folder and successfully inserts it into my database. Could you give me your advice on this point please?

This is my form excerpt. At the bottom is where I ask user to upload file:

<body>

    <form method='post' enctype="multipart/form-data" action="/hard">

        {{csrf_field()}}

        <section>
        <br>
            <legend><i><b> Complete Data Below</b></i></legend>
        <br>
        </section>

        <section>   
        Choose program:
            <select name="sc" id="xaos">

            <optgroup label="postgraduates">
                @foreach($transport as $y)
                    <option value="{{$y->object_id}}">{{$y->object_name}}</option>
                @endforeach
            </optgroup>

            </select>
        </section>

    <br>

        <section>
        ID number: 
            <input name='am' type='number' min="1000000" max="1999999" required="" oninvalid="this.setCustomValidity('1000000 < Value < 1999999')">
        </section>

        <br>

        <section>
        Select Language:
            <select name="language" id="lang">
                    <option value="GR"> Greek</option>
                    <option value="EN"> English</option>
            </select>
        </section>
        <br>
        <section>
        <label for="upload-file">select csv file</label>
            <input type="file" name="upload-file"> 
        </div>
            <input type='submit' name='upload' value="Submit!">
        </section>

    </form>
    <br>
    <br>

</body>

And below is my controller excerpt which is supposed to receive file. The issue is with fopen function. How can it handle the file imported from the form above?

public function job(Request $p)
    {
        $a1 = $p -> get('sc');
        $a2 = $p -> get('am'); 
        $a3 = $p -> get('language'); 




    $f_rownum = 0;

    if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 

    {
        while ( ($data = fgetcsv ( $handle, 1000, ';' )) !== FALSE )
        {
            $ac1=$data[0];
            $ac2=iconv("Windows-1253", "UTF-8", $data[1]);
            $ac3=iconv("Windows-1253", "UTF-8", $data[2]);
            $ac4=iconv("Windows-1253", "UTF-8", $data[3]);
            $ac5=$data[4];

......
19 May
4 weeks ago

konrms left a reply on Help With Csv File Uploading...

@DEVFREY - I have found that replacing ',' delimiter with ';' at my code excerpt

if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 0, ';' )) !== FALSE )
                dd($data);

and dd($data) fills all data. Just like below. The odd characters remain though.

array:73 [▼
  0 => "1040290"
  1 => b"ÐÁÐÁÄÇÌÇÔÑÉÏÕ, ÃÅÙÑÃÉÏÓ"
  2 => b"ÊÙÍÓÔÁÍÔÉÍÏÓ"
  3 => "234513"
  4 => "9198"
  5 => b"Áðüöïéôïò"
  6 => "5"
  7 => "STC_131"
  8 => b"ÄÉÁ×. ÓÕÍÈ. ÁÍÔÉÊ. ÐÏË.-ÌÅÓÙÍ ÓÅ Â. Ä."
  9 => "2014"
  10 => "20"
  11 => "2014"
  12 => "20"
  13 => "9,0"
  14 => ""
  15 => "2"
  16 => "1"
  17 => b"Ð"
  18 => b"ËÕ"
  19 => b"ÕÐÏ"
  20 => ""
  21 => "6,00"
  22 => "0,00"
  23 => b"ÐÌ"
  24 => "0,00"
  25 => "0,00"
  26 => b"ÄÌ"
  27 => "0,0"
  28 => "EG0STC_S2R1"
  29 => b"ËÕ 1ï ÅîÜìçíï Êïñìïý"
  30 => "EG0STC_SPEC"
  31 => b"Êáôåõèýíóåéò  ÅðéóôÞìçò &Ôå÷íïëïãßáò Ç/Õ"
  32 => "1"
  33 => "PR"
  34 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  35 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  36 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  37 => b"Äåßêôçò äåí Êáèïñßóôçêå"
  38 => b"Ìç Ìåôáöåñüìåíï"
  39 => b"Ï÷é"
  40 => b"Åêðñüèåóìç"
  41 => "1"
  42 => "27/03/2015"
  43 => b"Ìç ÁôïìéêÞ Åñãáóßá"
  44 => "0"
  45 => ""
  46 => ""
  47 => "EMBK"
  48 => "00155D6E0B0B1ED4AAD6D796E8DA83E3"
  49 => "00155D6E0B0B1ED4AAD6D796E8DA63E3"
  50 => "00155D6E0B0B1ED4AAD6D796E8DA63E3"
  51 => "50091351"
  52 => "EG0_STC"
  53 => b"Ð.Ì.Ó. ÅðéóôÞìç &Ôå÷í ÇÕ (-2017)"
  54 => "50086330"
  55 => "50091396"
  56 => "0"
  57 => "50091374"
  58 => "50091355"
  59 => ""
  60 => ""
  61 => ""
  62 => "0"
  63 => "01/09/2014"
  64 => "15/02/2015"
  65 => "02/02/2015"
  66 => b"10:37:36 ðì"
  67 => "0"
  68 => ""
  69 => "2"
  70 => "50098572"
  71 => "00155D6E0B0B1ED4AAD6D796E8D8A3E3"
  72 => ""
]

But when I remove dd and try to run code on the whole the error changes to this:

Error Code : 942 Error Message : ORA-00942: table or view does not exist Position : 12 Statement : insert into "CSVDATA" ("AC1", "AC2", "AC3", "AC4", "AC5", "AC6", "AC7", "AC8", "AC9", "AC10", "AC11", "AC12", "AC13", "AC14", "AC15", "AC16", "AC17", "AC18", "AC19", "AC20", "AC21", "AC22", "AC23", "AC24", "AC25", "AC26", "AC27", "AC28", "AC29", "AC30", "AC31", "AC32", "AC33", "AC34", "AC35", "AC36", "AC37", "AC38", "AC39", "AC40", "AC41", "AC42", "AC43", "AC44", "AC45", "AC46", "AC47", "AC48", "AC49", "AC50", "AC51", "AC52", "AC53", "AC54", "AC55", "AC56", "AC57", "AC58", "AC59", "AC60", "AC61", "AC62", "AC63", "AC64", "AC65", "AC66", "AC67", "AC68", "AC69", "AC70", "AC71", "AC72", "AC73") values (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20, :p21, :p22, :p23, :p24, :p25, :p26, :p27, :p28, :p29, :p30, :p31, :p32, :p33, :p34, :p35, :p36, :p37, :p38, :p39, :p40, :p41, :p42, :p43, :p44, :p45, :p46, :p47, :p48, :p49, :p50, :p51, :p52, :p53, :p54, :p55, :p56, :p57, :p58, :p59, :p60, :p61, :p62, :p63, :p64, :p65, :p66, :p67, :p68, :p69, :p70, :p71, :p72) returning "ID" into :p73

konrms left a reply on Help With Csv File Uploading...

@DEVFREY - Never mind! Once again, thanks for helping!

I changed code as follows:

public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //όνομα προγράμματος
        $a2 = $p -> get('am');  //αριθμός μητρώου φοιτητή
        $a3 = $p -> get('language');  //γλώσσα
        
        if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 0, ',' )) !== FALSE )
                dd($data);

The result I'm getting is below. Why those strange characters appear? They represent greek language words in .csv.

array:8 [▼
  0 => b"1040290;ÐÁÐÁÄÇÌÇÔÑÉÏÕ"
  1 => b" ÃÅÙÑÃÉÏÓ;ÊÙÍÓÔÁÍÔÉÍÏÓ;234513;9198;Áðüöïéôïò;5;STC_131;ÄÉÁ×. ÓÕÍÈ. ÁÍÔÉÊ. ÐÏË.-ÌÅÓÙÍ ÓÅ Â. Ä.;2014;20;2014;20;9"
  2 => b"0;;2;1;Ð;ËÕ;ÕÐÏ;;6"
  3 => "00;0"
  4 => b"00;ÐÌ;0"
  5 => "00;0"
  6 => b"00;ÄÌ;0"
  7 => b"0;EG0STC_S2R1;ËÕ 1ï ÅîÜìçíï Êïñìïý;EG0STC_SPEC;Êáôåõèýíóåéò  ÅðéóôÞìçò &Ôå÷íïëïãßáò Ç/Õ;1;PR;Äåßêôçò äåí Êáèïñßóôçêå;Äåßêôçò äåí Êáèïñßóôçêå;Äåßêôçò äåí Êáèïñßóôçêå;Äåßêôçò äåí Êáèïñßóôçêå;Ìç Ìåôáöåñüìåíï;Ï÷é;Åêðñüèåóìç;1;27/03/2015;Ìç ÁôïìéêÞ Åñãáóßá;0;;;EMBK;00155D6E0B0B1ED4AAD6D796E8DA83E3;00155D6E0B0B1ED4AAD6D796E8DA63E3;00155D6E0B0B1ED4AAD6D796E8DA63E3;50091351;EG0_STC;Ð.Ì.Ó. ÅðéóôÞìç &Ôå÷í ÇÕ (-2017);50086330;50091396;0;50091374;50091355;;;;0;01/09/2014;15/02/2015;02/02/2015;10:37:36 ðì;0;;2;50098572;00155D6E0B0B1ED4AAD6D796E8D8A3E3; ◀"
]

konrms left a reply on Help With Csv File Uploading...

@DEVFREY - I altered code according your recommendation. I'm getting again "Undefined offset: 8". The error page now highlights code line.

$csv_data->{'ac'.($index + 1)} = $data[$index];

The code excerpt is this. What else could I check?

    public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //όνομα προγράμματος
        $a2 = $p -> get('am');  //αριθμός μητρώου φοιτητή
        $a3 = $p -> get('language');  //γλώσσα
        
        if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 0, ',' )) !== FALSE )
                {
                    {
                        $csv_data = new Csvdata ();
                        
                        foreach(range(0, 72) as $index) 
                        {
                            $csv_data->{'ac'.($index + 1)} = $data[$index];
                        }

                        
                        $csv_data->save ();
                    }
                    fclose ( $handle );
                }
                $finalData = $csv_data::all ();
                dd($finalData);

........................

konrms left a reply on Help With Csv File Uploading...

@DEVFREY - Hello @devfrey ... Thanks for replying! I have updated form according to your recommendation. The problems persist though. I'm trying to stick to this guide https://justlaravel.com/import-csv-data-store-database/?utm_source=learninglaravel.net but now I get Undefined offset: 8 error. What could that be?

To sum up, all my actions so far are:

I have run php artisan make:migration create_csv_data_table at cmd I created the table fields to database\migrations csv_data_table I have migrated this to database ( php artisan migrate) and the table csv_data is created into my oracle db I have also created the correspondig model (with php artisan make:model Csvdata)

And below some code excerpts relative to the issue:

  1. web.php
Route::get('/diploma', '[email protected]');
Route::post('/hard', '[email protected]');

Route::get('/p', '[email protected]');
Route::get('/export1','[email protected]')->name('export1.pdf');
  1. form:
<form method='post' enctype="multipart/form-data" action="/hard">

        {{csrf_field()}}

        <section>
        <br>
            <legend><i><b> Συμπλήρωση Στοιχείων Παραρτήματος Διπλώματος</b></i></legend>
        <br>
        </section>

        <section>   
        Επιλογή Προγράμματος Σπουδών:
            <select name="sc" id="xaos">

            <optgroup label="postgraduates">
                @foreach($transport as $y)
                    <option value="{{$y->object_id}}">{{$y->object_name}}</option>
                @endforeach
            </optgroup>

            </select>
        </section>

    <br>

        <section>
        Αριθμός Μητρώου Φοιτητή: 
            <input name='am' type='number' min="1000000" max="1999999" required="" oninvalid="this.setCustomValidity('1000000 < Τιμή < 1999999')">
        </section>

        <br>

        <section>
        Επιλογή Γλώσσας:
            <select name="language" id="lang">
                    <option value="GR"> Greek</option>
                    <option value="EN"> English</option>
            </select>
        </section>

        <br>

        <section>
        <label for="upload-file">select csv file</label>
            <input type="file" name="upload-file" class="form-control">
        </div>
        <input class="btn btn-success" type="submit" value="Upload " name="submit">

        <section>
        <br>
            <input type='submit' value="Submit!">
        </section>

    </form>
  1. migrations file class:
class CreateCsvDataTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('csv_data', function (Blueprint $table) 
        {
            $table->integer('ac1')-> nullable();
            $table->string('ac2')-> nullable();
            $table->string('ac3')-> nullable();
            $table->integer('ac4')-> nullable();
            $table->integer('ac5')-> nullable();
            $table->string('ac6')-> nullable();
            $table->integer('ac7')-> nullable();
            $table->string('ac8')-> nullable();
            $table->string('ac9')-> nullable();
            $table->integer('ac10')-> nullable();
            $table->integer('ac11')-> nullable();
            $table->integer('ac12')-> nullable();
            $table->integer('ac13')-> nullable();
            $table->float('ac14')-> nullable();
            $table->integer('ac15')-> nullable();
            $table->integer('ac16')-> nullable();
            $table->integer('ac17')-> nullable();
            $table->string('ac18')-> nullable();
            $table->string('ac19')-> nullable();
            $table->string('ac20')-> nullable();
            $table->string('ac21')-> nullable();
            $table->integer('ac22')-> nullable();
            $table->float('ac23')-> nullable();
            $table->string('ac24')-> nullable();
            $table->float('ac25')-> nullable();
            $table->float('ac26')-> nullable();
            $table->string('ac27')-> nullable();
            $table->float('ac28')-> nullable();
            $table->string('ac29')-> nullable();
            $table->string('ac30')-> nullable();
            $table->string('ac31')-> nullable();
            $table->string('ac32')-> nullable();
            $table->integer('ac33')-> nullable();
            $table->string('ac34')-> nullable();
            $table->string('ac35')-> nullable();
            $table->string('ac36')-> nullable();
            $table->string('ac37')-> nullable();
            $table->string('ac38')-> nullable();
            $table->string('ac39')-> nullable();
            $table->string('ac40')-> nullable();
            $table->string('ac41')-> nullable();
            $table->integer('ac42')-> nullable();
            $table->date('ac43')-> nullable();
            $table->string('ac44')-> nullable();
            $table->string('ac45')-> nullable();
            $table->string('ac46')-> nullable();
            $table->string('ac47')-> nullable();
            $table->string('ac48')-> nullable();
            $table->string('ac49')-> nullable();
            $table->string('ac50')-> nullable();
            $table->string('ac51')-> nullable();
            $table->string('ac52')-> nullable();
            $table->string('ac53')-> nullable();
            $table->string('ac54')-> nullable();
            $table->integer('ac55')-> nullable();
            $table->integer('ac56')-> nullable();
            $table->integer('ac57')-> nullable();
            $table->integer('ac58')-> nullable();
            $table->integer('ac59')-> nullable();
            $table->string('ac60')-> nullable();
            $table->string('ac61')-> nullable();
            $table->string('ac62')-> nullable();
            $table->integer('ac63')-> nullable();
            $table->date('ac64')-> nullable();
            $table->date('ac65')-> nullable();
            $table->date('ac66')-> nullable();
            $table->string('ac67')-> nullable();
            $table->integer('ac68')-> nullable();
            $table->string('ac69')-> nullable();
            $table->integer('ac70')-> nullable();
            $table->integer('ac71')-> nullable();
            $table->string('ac72')-> nullable();
            $table->string('ac73')-> nullable();

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('csv_data');
    }
}
  1. Controller excerpt (when pressing upload at my form I get Undefined offset: 8 error and line $csv_data->ac9 =$data [8]; is marked)
public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //όνομα προγράμματος
        $a2 = $p -> get('am');  //αριθμός μητρώου φοιτητή
        $a3 = $p -> get('language');  //γλώσσα

        if (($handle = fopen ( 'MOCK_DATA.csv', 'r' )) !== FALSE) 
        {
            while ( ($data = fgetcsv ( $handle, 1000, ',' )) !== FALSE )
                {
                    {
                        $csv_data = new Csvdata ();
                        $csv_data->ac1  =$data [0];
                        $csv_data->ac2  =$data [1];
                        $csv_data->ac3  =$data [2];
                        $csv_data->ac4  =$data [3];
                        $csv_data->ac5  =$data [4];
                        $csv_data->ac6  =$data [5];
                        $csv_data->ac7  =$data [6];
                        $csv_data->ac8  =$data [7];
                        $csv_data->ac9  =$data [8];
                        $csv_data->ac10 =$data [9];
                        $csv_data->ac11 =$data [10];
                        $csv_data->ac12 =$data [11];
                        $csv_data->ac13 =$data [12];
                        $csv_data->ac14 =$data [13];
                        $csv_data->ac15 =$data [14];
                        $csv_data->ac16 =$data [15];
                        $csv_data->ac17 =$data [16];
                        $csv_data->ac18 =$data [17];
                        $csv_data->ac19 =$data [18];
                        $csv_data->ac20 =$data [19];
                        $csv_data->ac21 =$data [20];
                        $csv_data->ac22 =$data [21];
                        $csv_data->ac23 =$data [22];
                        $csv_data->ac24 =$data [23];
                        $csv_data->ac25 =$data [24];
                        $csv_data->ac26 =$data [25];
                        $csv_data->ac27 =$data [26];
                        $csv_data->ac28 =$data [27];
                        $csv_data->ac29 =$data [28];
                        $csv_data->ac30 =$data [29];
                        $csv_data->ac31 =$data [30];
                        $csv_data->ac32 =$data [31];
                        $csv_data->ac33 =$data [32];
                        $csv_data->ac34 =$data [33];
                        $csv_data->ac35 =$data [34];
                        $csv_data->ac36 =$data [35];
                        $csv_data->ac37 =$data [36];
                        $csv_data->ac38 =$data [37];
                        $csv_data->ac39 =$data [38];
                        $csv_data->ac40 =$data [39];
                        $csv_data->ac41 =$data [40];
                        $csv_data->ac42 =$data [41];
                        $csv_data->ac43 =$data [42];
                        $csv_data->ac44 =$data [43];
                        $csv_data->ac45 =$data [44];
                        $csv_data->ac46 =$data [45];
                        $csv_data->ac47 =$data [46];
                        $csv_data->ac48 =$data [47];
                        $csv_data->ac49 =$data [48];
                        $csv_data->ac50 =$data [49];
                        $csv_data->ac51 =$data [50];
                        $csv_data->ac52 =$data [51];
                        $csv_data->ac53 =$data [52];
                        $csv_data->ac54 =$data [53];
                        $csv_data->ac55 =$data [54];
                        $csv_data->ac56 =$data [55];
                        $csv_data->ac57 =$data [56];
                        $csv_data->ac58 =$data [57];
                        $csv_data->ac59 =$data [58];
                        $csv_data->ac60 =$data [59];
                        $csv_data->ac61 =$data [60];
                        $csv_data->ac62 =$data [61];
                        $csv_data->ac63 =$data [62];
                        $csv_data->ac64 =$data [63];
                        $csv_data->ac65 =$data [64];
                        $csv_data->ac66 =$data [65];
                        $csv_data->ac67 =$data [66];
                        $csv_data->ac68 =$data [67];
                        $csv_data->ac69 =$data [68];
                        $csv_data->ac70 =$data [69];
                        $csv_data->ac71 =$data [70];
                        $csv_data->ac72 =$data [71];
                        $csv_data->ac73 =$data [72];

                        $csv_data->save ();
                    }
                    fclose ( $handle );
                }
                $finalData = $csv_data::all ();
                dd($finalData);
18 May
4 weeks ago

konrms started a new conversation Help With Csv File Uploading...

Hello guys. I'm trying to upload a .csv file to my (oracle) database. In fact the end user should insert this file along with other data. After submitting, a pdf file should be created.

I have created class CreateCsvDataTable (php migrate) with schema csv_data and the table csv_data exists in my oracle. It should be populated without headers.

My trouble is with csv uploading (please have a look at point (3)). When giving dd($header); I get this error:

Call to a member function getRealPath() on null

Could you please assist?

(1) My web.php routes file is the following:

Route::get('/diploma', '[email protected]');
Route::post('/hard', '[email protected]');

Route::get('/p', '[email protected]');
Route::get('/export1','[email protected]')->name('export1.pdf');

(2) The form code (blade excerpt) with data requested is this:

    <form method='post' action="/hard">
    
        {{csrf_field()}}
        

        
        <section>   
        Choose program:
            <select name="sc" id="xaos">
        
            <optgroup label="postgraduates">
                @foreach($transport as $y)
                    <option value="{{$y->object_id}}">{{$y->object_name}}</option>
                @endforeach
            </optgroup>
        
            </select>
        </section>
    
    <br>

        <section>
        AM: 
            <input name='am' type='number' min="1000000" max="1999999" required="" oninvalid="this.setCustomValidity('1000000 < Value < 1999999')">
        </section>
        
        <br>
        
        <section>
        Select language:
            <select name="language" id="lang">
                    <option value="GR"> Greek</option>
                    <option value="EN"> English</option>
            </select>
        </section>
        
        <br>
        
        <section>
        <label for="upload-file">select csv file</label>
            <input type="file" name="upload-file" class="form-control">
        </div>
        <input class="btn btn-success" type="submit" value="Upload " name="submit">

        <section>
        <br>
            <input type='submit' value="Submit!">
        </section>
        
    </form>

(3) And the PdfController.php excerpt regarding form input data get is this:

public function job(Request $p)
    {
        $a1 = $p -> get('sc');  //works!
        $a2 = $p -> get('am');  //works!
        $a3 = $p -> get('language');  //works!
        
        //get csv file                          
        $upload = $p -> file('upload-file');
        $filePath = $upload ->getRealPath(); --> HELP NEEDED HERE!!
        
        //open and read file
        $file = fopen($filePath, 'r');
        $header = fgetcsv($file); //I want to insert data without header
        
        dd($header);
15 May
1 month ago

konrms left a reply on Date Format In Laravel Controller

@CORCRONJE - That's it! It worked!

I know it returns string. I may alter that later but it's on purpose for now.

Thanks a lot!

konrms left a reply on Date Format In Laravel Controller

@corcronje

Thanks for helping me!

My table ( 1x5) is this:

first_name last_name id date_of_birth city Dimitra Ioan 312312 19/04/95 New York

  1. Controller (only consider 'mydate => $d):

My query is this

$d = DB::table('student_data')->value('date_of_birth');

//code blalba...

return view('exagogi', ['epwnymo' => $a, 'onoma' => $b, 'arithmos' => $c, 'mydate => $d, 'xwra' => $e]);
  1. exagogi.blade
<!DOCTYPE html>


<head>

....

</head>
<body>

....

1.4 &nbsp;Date of Birth (day/month/year):&nbsp;{{$mydate}}  <!-- the result here is "1995-04-19 00:00:00" -->

....
</body>
<html>

konrms left a reply on Date Format In Laravel Controller

Hi @corcronje and @nakov

unfortunately I get errors. I tried this at my blade

{{ \Carbon\Carbon::parse($mydate->endda)->format('d/m/Y')}}

but also fails...

konrms left a reply on Date Format In Laravel Controller

@CORCRONJE - Hi @corcronje

I tested it but this returns error:

Call to a member function format() on string

I also got the same error when I alter my code as

$d->format('dd/mm/Y');
dd($d);

In fact I want to pass this date data to a blade. At least, is it possible to alter date format in blade?

konrms started a new conversation Date Format In Laravel Controller

Hello guys.

I retrieve some data from my database student_data table. The date of birth inside the table is 19/04/95. (The format is dd/mm/yy). The data is retrieved with this command:

$d = DB::table('student_data')->value('date_of_birth');

But testing with dd($d) gives me this result:

"1995-04-19 00:00:00"

How can I alter dd($d) result to show date as follows?

19/04/1995

Thanks in advance.

21 Apr
1 month ago

konrms left a reply on Global Variable In Controller

@JLRDW - Hi jlrdw.

Yes, I want to be transferred to another function in the same controller only.

If I add the following line to Roger

$this -> Roger1($p); 

I get this (?):

Request {#42 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure($guard = null) {#211 ▶}
  #routeResolver: Closure() {#213 ▶}
  +attributes: ParameterBag {#44 ▶}
  +request: ParameterBag {#43 ▶}
  +query: ParameterBag {#50 ▼
    #parameters: []
  }
  +server: ServerBag {#46 ▶}
  +files: FileBag {#47 ▶}
  +cookies: ParameterBag {#45 ▶}
  +headers: HeaderBag {#48 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/hard"
  #requestUri: "/hard"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Store {#248 ▼
    #id: "y3kO9bIBPS3WiQIwyynz27yO5mbFBUHWZ7vyBnJ6"
    #name: "laravel_session"
    #attributes: array:3 [▶]
    #handler: FileSessionHandler {#249 ▶}
    #started: true
  }
  #locale: null
  #defaultLocale: "en"
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}
20 Apr
1 month ago

konrms started a new conversation Global Variable In Controller

Hello guys.

I want to create a varible which should be available in two different controller functions. How can I do that?

For example, the first function gets data from a blade and I want to pass it to another function in the same controller. My code sample is this:

  1. The blade which sends obj_id:
<!DOCTYPE html>

<html>
<meta charset="UTF-8">
<head>

<title>test</title>
</head>


<body>

    <form method='post' action="/hard">
        {{csrf_field()}}
        <br>
        <legend><i> fill number </i></legend>
        <br>
        <label>
            OBJECT ID:
            <input name='obj_id' type='text' minlength="8" required="" oninvalid="this.setCustomValidity('At least 8 characters must be used)">
        </label>
        <br>

        <input type='submit' value="Υποβολή!">
    </form>
    <br>
    <br>
    
</body>
</html>
  1. This is my controller function Roger which gets obj_id from blade.
public function Roger(Request $p)
    {
        $t = $p-> get('obj_id');   //I want $ to be available to other controller functions
            
    }
  1. How to pass $t to another function (e.g. Roger1) in the same blade and just dd it?
public function Roger1()
    {
        
        dd(t);
    }

I have tried to declade global t but didn't work.

Thanks a lot!

15 Apr
2 months ago

konrms left a reply on How To Export Laravel Blade To Word Document

@SNAPEY - I think it's not that simple. Because the export to word module needs user data input to work... Just requesting the file export does not provide data necessary to run query in new controller.. Unless I create a secondary db table which stores data from query and the using a second query in the new controller that would retrieve data necessary to provide to export module. But that's too much I'd say.

konrms left a reply on How To Export Laravel Blade To Word Document

@SNAPEY - Yes, I agree this youtube example does not work for frameworks. But the result is exactly what I'm now trying to implement!

I'm now facing an issue with fetching data from blade to controller (according to your solution recommendation). I know how to send data from controller to blade eg

return view ('sam', ['onoma' => $m, 'epitheto' => $n]);

and then process it in blade with

First Name: <b> {{ $onoma }}</b><br>
Last Name: <b> {{ $epitheto }}</b><br>

but have difficulty in the opposing process. I mean how can I send $onoma and $epitheto to a desired controller via blade?

konrms left a reply on How To Export Laravel Blade To Word Document

@BOBBYBOUWMANN - The export to word is done inside the controller. I must do it in blade if possible. In the near future I will need to export to a word template. My idea was to create the word template as a blade and then to export page to document.

For now I'm just practicing with something much simpler; to export just the first and last name from an oracle table. My code is below:

The code below gets obj_id inserted by user from html page. I have created a form in a blade which transfers this data. Variables $m and $n get first and last name from hrp1702 table. The part below that point ($wordTest = ...) performs exporting to word. It does work but this is not what I'm trying to do.

    
    public function work(Request $bb)
    {
        
                
        $cc = $bb -> get('obj_id');
        
        
        $m = DB::table('hrp1702') -> where('object_id', $cc)->value('first_name');
        $n = DB::table('hrp1702') -> where('object_id', $cc)->value('last_name');
        
            
        
        $wordTest = new \PhpOffice\PhpWord\PhpWord();
        $newSection = $wordTest->addSection();
        
        $newSection->addText('FIRST NAME: '.$m);
        $newSection->addText('LAST NAME: '.$n);
        
        $objectWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordTest, 'Word2007');
        try 
        {
            $objectWriter->save(storage_path('TestWordFile.docx'));
        } 
        catch (Exception $e) 
        {
        }
    
        return response()->download(storage_path('TestWordFile.docx'));

            
    }
    
}       

IN FACT I want to alter this code as follows (BUT THIS DOES NOT WORK):

public function work(Request $bb)
    {
        
                
        $cc = $bb -> get('obj_id');
        
        
        $m = DB::table('hrp1702') -> where('object_id', $cc)->value('first_name');
        $n = DB::table('hrp1702') -> where('object_id', $cc)->value('last_name');
        
        return view ('sam', ['onoma' => $m, 'epitheto' => $n]);
    }

And the sam.blade

<!DOCTYPE html>

<html lang="el">
<head>
    <meta charset="UTF-8">
    <title>Full Name</title>
</head>
<body>
{{csrf_field()}}


First Name: <b> {{ $onoma }}</b><br>
Last Name: <b> {{ $epitheto }}</b><br>


<br>

<form method="post" action='/exagogi'>

    
    <input type="submit" value="Export to Word" />   //I want to press Export to Word key to produce doc.
</form>

</body>
</html>
14 Apr
2 months ago

konrms left a reply on How To Export Laravel Blade To Word Document

@BOBBYBOUWMANN - I tried to implement the youtube link I pasted into my previous reply in a blade. I don't know if that's the proper way in laravel, but gives me errors when running it. If I can't export a form blade into document I was wondering if it'd be possible to implement it using controllers variables. One other thing I haven't yet made out at github's package instructions (https://github.com/PHPOffice/PHPWord) is about the php code example. It should be inside the blade? I'm very novice and try to learn. I have implemented some projects and try to improve.

konrms left a reply on How To Export Laravel Blade To Word Document

@BOBBYBOUWMANN - First of all I'm not getting paid for this. I'm not a professional. I do it for personal knowledge. if you can help somehow then assist, otherwise let it go. I have already read all the stuff you've sent. It does what it does in a controller. I want to add export to word in a blade. I want something like that https://www.youtube.com/watch?v=iqCOgIzoNpQ&t=195s but is fails in my case.

konrms started a new conversation How To Export Laravel Blade To Word Document

I want to add export to word functinality to one of my blades in Laravel. I have also asked that at stackoverflow hoping to get some help!

I have already run

composer require phpoffice/phpword

at cmd but I can't succesfully implement my export. Below you can see the blade I want to export to word. It is a very simple blade which takes fist and last name from a db table. I want to add a button at the bottom that exports to word on click. Could you assist please?

<!DOCTYPE html>

<html lang="el">
<head>
    <meta charset="UTF-8">
    <title>Full Name</title>
</head>
<body>

First Name: <b> {{ $onoma }}</b><br>
Last Name: <b> {{ $epitheto }}</b><br>



</body>
</html>
10 Apr
2 months ago

konrms left a reply on How To Access Laravel Site From Another Computer

@JAMESFREEMAN - I have never tried port forwarding with my router. I will search how to. I'm not going to use it for too long, just for self learning purposes. When our project goes live we will use a dedicated server for it. For now I use xampp apache server.

09 Apr
2 months ago

konrms left a reply on How To Access Laravel Site From Another Computer

@JAMESFREEMAN - I think this is the solution "Set up their host file with 192.168.1.101 laravel.site". In the case of outside lan pc's what can I do? Port forwading from my router?

konrms left a reply on How To Access Laravel Site From Another Computer

@MCANGUEIRO - Hello MCANGUEIRO. Thanks for replying to me. I'll have a look at ngrok. I guess that's for external routing. For the LAN case I guess it's matter of setting up correctly dns service inside apache server configuration.

08 Apr
2 months ago

konrms started a new conversation How To Access Laravel Site From Another Computer

Hello guys.

I need some help on how to access my site running on my pc from another device in case the other device belongs: (1) to the same LAN and (2) outside LAN.

I am using XAMPP Apache server. On my pc I simply browse to page laravel.site and fully access my site.

  • What I have done so far and partially works for LAN case:

At cmd I ran c:\xampp\htdocs\laravel\php artisan serve --host 192.168.1.101 --port 5000, (where 192.168.1.101 is my local ip address). In this case, when browsing to 192.168.1.101:5000 I can see my site's first page. But when clicking on site links I get a dns error. I can only indirectly access other site routes with 192.168.1.101:5000/[route]

For your info, my C:\Windows\System32\drivers\etc\hosts file line regarding laravel is:

127.0.0.1   laravel.site

and my C:\xampp\apache\conf\extra\httpd-vhosts excerpt for laravel is the following:

# VirtualHost for LARAVEL.DEV
<VirtualHost laravel.site:80>
  DocumentRoot "C:\xampp\htdocs\laravel\public"
  ServerAdmin laravel.site
  <Directory "C:\xampp\htdocs\laravel">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
  </Directory>
</VirtualHost>
##</VirtualHost>
13 Mar
3 months ago

konrms started a new conversation Shibboleth Authentication

Has anyone here interfered with shibboleth package? Any idea is valuable! I have made a request at stackoverflow too but with no result.

I am trying to add this authentication package to my project. My laravel version is 5.7.26. I have followed these instructions https://packagist.org/packages/uabookstores/laravel-shibboleth?fbclid=IwAR1fBHLv_0EPgS2hhNc5fB2AVF_ZjOthpPVu_yCgLzySfLYXX-dRSTucCBc but I can not implement users login (and have not understood how to use it).

I'm stuck at this point:

@if (Auth::guest())
    <a href="/shibboleth-login">Login</a>
@else
    <a href="/shibboleth-logout">
        Logout {{ Auth::user()->name }}
    </a>
@endif
04 Mar
3 months ago

konrms left a reply on How To Export Database Table To Excel File In Laravel

Guys, I did it on the whole. So the total solution is below:

  1. web.php
Route::get('/exagogi','[email protected]');
  1. UsersExport.php (App\Exports\UsersExport.php)
<?php

namespace App\Exports;

use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings; 

class UsersExport implements FromCollection, WithHeadings
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return User::all();
    }

    public function headings(): array
    {
        return [
            'Lesson Category',
            'Lesson Title',
            'Lesson Department'
        // etc


        ];
    }
}
  1. UsersController.php
<?php namespace App\Http\Controllers;

use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class UsersController extends Controller 
{
    public function export() 
    {
        return Excel::download(new UsersExport, 'result.xlsx');
    }
}

konrms left a reply on How To Export Database Table To Excel File In Laravel

@JORICKL - Thank you very much! I should also thank @aurawindsurfing too.

Well I just managed to export to excel! After many many tests and failures.

But there is one thing left... I want my exported excel to have title in every table field on top and not only the table data copied into sheet. Any idea is very welcome!

For your info, my code is the following (for the whole solution, of course there should be applied these prerequisites too https://docs.laravel-excel.com/3.1/exports/).

https://docs.laravel-excel.com/3.1/getting-started/installation.html :

  1. web.php:
Route::get('/exagogi','[email protected]');
  1. UsersExport.php (App\Exports\UsersExport.php)
<?php

namespace App\Exports;

use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;

class UsersExport implements FromCollection
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return User::all();
    }
}
  1. UsersController.php
<?php namespace App\Http\Controllers;

use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class UsersController extends Controller 
{
    public function export() 
    {
        return Excel::download(new UsersExport, 'users.xlsx');
    }
}
03 Mar
3 months ago

konrms left a reply on How To Export Database Table To Excel File In Laravel

@JORICKL - For being on the safe side, I renamed formal table to users table in my database and query and retested everything. Now when pressing the export to excel button I get an empty page. I searched my pc for the users.xlsx file (which was supposed to be created in my downloads folder) but nothing was found anywhere.

I followed these two guides step by step: https://docs.laravel-excel.com/3.1/getting-started/installation.html https://docs.laravel-excel.com/3.1/exports/.

Could you help me with my code please? I have all necessary items below.

The blade excerpt is below:

<form action='/exagogi'>
    <input type="submit" value="Export to excel" />
</form>

My web.php excerpt is this:

Route::get('/exagogi', '[email protected]');

My whole UsersController is this:

<?php namespace App\Http\Controllers;

use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;


class UsersController extends Controller
{
        
    public function export()
    {
        //return ('Trying to add export to excel function!');
        Excel::download(new UsersExport, 'users.xlsx');
    }
    
}       

and my app\Exports\UsersExport is below:

<?php

namespace App\Exports;

use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;

class UsersExport implements FromCollection
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return User::all();
    }
}
02 Mar
3 months ago

konrms left a reply on How To Export Database Table To Excel File In Laravel

@JORICKL - Hi Jorickl and @aurawindsurfing !

I replaced post with get at my web.php as below.

Route::get('/exagogi', '[email protected]');

When testing this case, I get error too as below (even if I directly enter http://laravel.site/exagogi: into browser line).

C:\xampp\htdocs\laravel\app\Exports\FormalExport.php
<?php
 
namespace App\Exports;
 
use App\formal;
use Maatwebsite\Excel\Concerns\FromCollection;
 
class FormalExport implements FromCollection
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return formal::all();
    }
}
 
Arguments
"Class 'App\formal' not found"

My FormalController.php is the following. If I uncomment return ('Hello'); line and comment return Excel::download(new FormalExport, 'formal.xlsx'); I get Hello message as expected.

<?php namespace App\Http\Controllers;

use App\Exports\FormalExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request; 



class FormalController extends Controller
    {
        public function exporting() 
        {
            //return ('Hello!');
        return Excel::download(new FormalExport, 'formal.xlsx');
        }
    }       
01 Mar
3 months ago

konrms left a reply on How To Export Database Table To Excel File In Laravel

@AURAWINDSURFING - Hello my friend!

I followed this: https://docs.laravel-excel.com/3.1/getting-started/installation.html and this: https://docs.laravel-excel.com/3.1/exports/

The result is this error Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException Can it be fixed?

konrms started a new conversation How To Export Database Table To Excel File In Laravel

Hi guys.

I'm trying to export the table "formal", to a simple excel file. I have installed the packet necessary with "composer require maatwebsite/excel" command from cmd and also have edited my app.php file adding "Maatwebsite\Excel\ExcelServiceProvider::class," to providers and "'Excel' => Maatwebsite\Excel\Facades\Excel::class," to aliases.

My blade successfully shows "formal" as html. Now I have added a second button with export to excel option. Unfortunately, I'm getting an error "Call to undefined method Maatwebsite\Excel\Excel::create()" when pressing "Download excel button".

Could you help me please?

This is my blade with the "Download excel" button added.

<!DOCTYPE html>
<html lang="el">
<head>
    <meta charset="UTF-8">
    <title>Πρόγραμμα Σπουδών</title>
    
</head>
<body>

<b>Πρόγραμμα Σπουδών: {{ $key }}</b>
<br>
<br>

<table border="1">
    <tr>
        <th>Κατηγορία μαθήματος</th>
        <th>Κωδικός μαθήματος</th>
        <th>Τίτλος μαθήματος</th>
        <th>Τμήμα μαθήματος</th>
        <th>ΠΜΣ</th>
        <th>Εργαστηριακή Μονάδα</th>
        <th>Τμήμα Εργαστηριακής μονάδας</th>
        <th>Username Upnet Διδάσκοντος</th>
        <th>Επίθετο Διδάσκοντος</th>
        <th>Όνομα Διδάσκοντος</th>
        <th>Τμήμα Διδάσκοντος</th>
        <th>Βαθμίδα Διδάσκοντος</th>
        <th>Ακαδημαϊκό εξάμηνο</th>
        <th>Υποχρεωτικό Μάθημα</th>
        <th>Συνδιδασκαλία</th>
        <th>Ακροατήριο</th>
    </tr>
    @foreach($star as $v2)
    <tr>
        <th>{{ $v2->lesson_category }}</th>
        <td>{{ $v2->lesson_code }}</td>
        <td>{{ $v2->lesson_title }}</td>
        <td>{{ $v2->lesson_dep }}</td>
        <td>{{ $v2->pms }}</td>
        <td>{{ $v2->ergastitiaki_monada }}</td>
        <td>{{ $v2->tmima_ergastitiakis_monadas }}</td>
        <td>{{ $v2->username }}</td>
        <td>{{ $v2->epitheto }}</td>
        <td>{{ $v2->onoma }}</td>
        <td>{{ $v2->tutor_dep }}</td>
        <td>{{ $v2->vathmida }}</td>
        <td>{{ $v2->semester }}</td>
        <td>{{ $v2->ypoxreotiko }}</td>
        <td>{{ $v2->syndidaskalia }}</td>
        <td>{{ $v2->akroatirio }}</td>
    </tr>
    @endforeach
</table>
<br>


<form action = '/excel'>
    <input type="submit" value="Download excel">
<form>


<form action ='/programma'>
    <input type="submit" value="Νέα Αναζήτηση" />
</form>


</body>
</html>

This is the ExportExcelController:

<?php namespace App\Http\Controllers;

use Illuminate\Http\Request;  
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\DB;  

class ExportExcelController extends Controller
{
    public function excel()
    {
        $formal_data = DB::table('formal')->get()->toArray();
        $programma_array[] = array('lesson_category', 'lesson_code', 'lesson_title', 'lesson_dep', 'pms',
        'ergastitiaki_monada', 'tmima_ergastitiakis_monadas', 'username', 'epitheto', 'onoma', 'tutor_dep', 'vathmida', 
        'semester', 'ypoxreotiko', 'syndidaskalia', 'akroatirio');
            
        foreach($formal_data as $pass)
        {
            $programma_array[] = array
            (
            'lesson_category'  => $pass->lesson_category,
            'lesson_code'   => $pass->lesson_code,
            'lesson_title'    => $pass->lesson_title,
            'lesson_dep'  => $pass->lesson_dep,
            'pms'   => $pass->pms,
            'ergastitiaki_monada'   => $pass->ergastitiaki_monada,
            'tmima_ergastitiakis_monadas'   => $pass->tmima_ergastitiakis_monadas,
            'username'   => $pass->username,
            'epitheto'   => $pass->epitheto,
            'onoma'   => $pass->onoma,
            'tutor_dep'   => $pass->tutor_dep,
            'vathmida'   => $pass->vathmida,
            'semester'   => $pass->semester,
            'ypoxreotiko'   => $pass->ypoxreotiko,
            'syndidaskalia'   => $pass->syndidaskalia,
            'akroatirio'   => $pass->akroatirio,                
            );
            
        }
        
            
            Excel::create('Programma_Data', function($excel) use ($programma_array)
            {
                $excel->setTitle('Apotelesmata');
                $excel->sheet('Programma_Data', function($sheet) use ($programma_array)
                {
                    $sheet->fromArray($programma_array, null, 'A1', false, false);
                });
            }) -> download('xlsx');
            
            
    }
               
}       

And my web.php

Route::get('/excel', '[email protected]')->name('export_excel.excel');
21 Feb
3 months ago

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

@TRAY2 - Me too ;). I'd be much happier if I could do it with eloquent and no raws, but still it's a decent solution. At least I'm declaring tables with schemas. I have a long way to go!

20 Feb
3 months ago

konrms left a reply on Translate Oracle Query Into Laravel

Finally I figured out the solution. I was directly inserting the whole query into DB which caused problems. I should have first assign it to string. In case someone has relevant issues with queries, that's the solution.

    $q = "insert into temp(object_type, object_id)";
    $q = $q."select distinct hrp1001_cg.object_type, hrp1001_cg.object_id from 
    hrp1001_cg, hrp1001_sc, config where";
    $q =$q." hrp1001_sc.object_type = 'CG'";
    $q = $q." and hrp1001_sc.rel_obj_type = 'SC'";
    $q = $q." and hrp1001_sc.rel_obj_id = config.sc";
    $q = $q." and hrp1001_sc.st_date < config.des_date";
    $q = $q." and hrp1001_sc.end_date > config.des_date";
    $q = $q." and hrp1001_cg.rel_obj_id = hrp1001_sc.object_id";
    $q = $q." and";
    $q = $q." ((hrp1001_cg.object_type = 'CG') or (hrp1001_cg.object_type = 'SM'))";

    $xx = DB::insert($q);

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

@TRAY2 - Finally I figured out the solution. It was simple. My mistake was that I was directly inserting the whole query into DB. I should have first assign it to string. So below is my code excerpt which is tested and working.

    $q = "insert into temp(object_type, object_id)";
    $q = $q."select distinct hrp1001_cg.object_type, hrp1001_cg.object_id from 
    hrp1001_cg, hrp1001_sc, config where";
    $q =$q." hrp1001_sc.object_type = 'CG'";
    $q = $q." and hrp1001_sc.rel_obj_type = 'SC'";
    $q = $q." and hrp1001_sc.rel_obj_id = config.sc";
    $q = $q." and hrp1001_sc.st_date < config.des_date";
    $q = $q." and hrp1001_sc.end_date > config.des_date";
    $q = $q." and hrp1001_cg.rel_obj_id = hrp1001_sc.object_id";
    $q = $q." and";
    $q = $q." ((hrp1001_cg.object_type = 'CG') or (hrp1001_cg.object_type = 'SM'))";

    $xx = DB::insert($q);

konrms left a reply on Translate Oracle Query Into Laravel

@JLRDW - The working query is huge and is consisted of 2 parts! I'm just at the first steps of implementation. It uses many db tables. I will show you the first part for now.

In laravel I have modified the way users input data (which is just the current date and the SC). In laravel, users just enter the SC number (the current date is automatically entered as below). The SC is entered in a blade.

use Carbon\Carbon;

$test = array
        (
            'sc' => $SC, 
            'des_date' => $we
        );
        
        DB::table('config') -> insert($test);

And this is the standard oracle query. This is what I'm trying to implement. I'm badly stuck and desperate!

DROP TABLE RESULT;

CREATE TABLE RESULT 
(
KODIKOS_MATHIMATOS  VARCHAR2(64)    NULL,
TITLOS_MATHIMATOS   VARCHAR2(128)   NULL,
TMHMA_MATHIMATOS       VARCHAR2(128)   NULL,
LESSON_ID                   INT             NULL,
PMS1                    VARCHAR2(256)   NULL,
PMS                 VARCHAR2(256)       NULL,
TUTOR_ID                    INT     NULL,
USERNAME        VARCHAR2(64)    NULL,
EPITHETO_DID        VARCHAR2(64)    NULL,
ONOMA_DID       VARCHAR2(64)    NULL,
TMHMA_DID       VARCHAR2(64)    NULL,
BATHMIDA_DID        VARCHAR2(64)    NULL,
SEMESTER        INT     NULL,
YPOXREOTIKO_MATH    INT     NULL
);

DROP TABLE ALPHA;

CREATE TABLE ALPHA
(
ADATA VARCHAR2(64) NULL
);

DROP TABLE T1;

CREATE TABLE T1  
(
ADATA   VARCHAR2(64)    NULL,
TEXT    VARCHAR2(256)   NULL
);

DROP TABLE T1T2;

CREATE TABLE T1T2
(
ADATA   VARCHAR2(64)    NULL,
TEXT    VARCHAR2(256)   NULL
);


DROP TABLE CONFIG;

CREATE TABLE CONFIG
(
SC  INT NULL,
DES_DATE    DATE
);

INSERT INTO CONFIG VALUES  
(50000026, '20/02/2019'); 

DROP TABLE TEMP;

CREATE TABLE TEMP
(
OBJECT_TYPE VARCHAR2(64)    NULL,
OBLECT_ID   INT     NULL
);

INSERT INTO TEMP (OBJECT_TYPE, OBLECT_ID)
SELECT DISTINCT HRP1001_CG.OBJECT_TYPE, HRP1001_CG.OBJECT_ID FROM HRP1001_SC, HRP1001_CG, CONFIG
WHERE
(HRP1001_SC.OBJECT_TYPE = 'CG')  
AND
(HRP1001_SC.REL_OBJ_TYPE = 'SC')   
AND
(HRP1001_SC.REL_OBJ_ID = CONFIG.SC)
AND
((HRP1001_SC.ST_DATE < CONFIG.DES_DATE) AND (HRP1001_SC.END_DATE > CONFIG.DES_DATE))
AND
(HRP1001_CG.REL_OBJ_ID = HRP1001_SC.OBJECT_ID)
AND
((HRP1001_CG.OBJECT_TYPE ='CG') OR (HRP1001_CG.OBJECT_TYPE ='SM'))
ORDER BY HRP1001_CG.OBJECT_ID;


BEGIN
FOR I IN 1..5
LOOP
INSERT INTO TEMP (OBJECT_TYPE, OBLECT_ID)
SELECT DISTINCT HRP1001_CG.OBJECT_TYPE, HRP1001_CG.OBJECT_ID FROM HRP1001_CG, TEMP, CONFIG
WHERE
(HRP1001_CG.REL_OBJ_ID = TEMP.OBLECT_ID)
AND
((HRP1001_CG.ST_DATE < CONFIG.DES_DATE) AND (HRP1001_CG.END_DATE > CONFIG.DES_DATE))
AND
((HRP1001_CG.OBJECT_TYPE ='CG') OR (HRP1001_CG.OBJECT_TYPE ='SM'))
ORDER BY HRP1001_CG.OBJECT_ID;
END LOOP;
END;

I have though of something else... In oracle sql developer there is a way to run queries as script. For example I can run the queries as below. Is there a way to do the same using laravel?

@c:\test\part1.txt;
@c:\test\part2.txt;  
19 Feb
3 months ago

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

@TRAY2 - Thank you for your advice! The ideal would be to make the DB:raw to work somehow . I can't understand what's wrong with it. I've asked for help at stackoverflow too, but you are the one and only who has responded. Thank you so much for that.

I didn't know about the db procedures. I'll try to search about how to. I have to find a way fast.

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

@TRAY2 - In fact this is a part of a bigger query. If I succeed with this excerpt I wil proceed with my code. Temp data will be used afterwards. Now I'm badly stuck and cannot proceed with my work.

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

In fact this is a part of a bigger query. If I succeed with this excerpt I wil proceed with my code. Temp data will be used afterwards. Now I'm badly stuck and cannot proceed with my work..

konrms started a new conversation Translate Oracle Query Into Laravel

Hi all.

Can anyone help me with my issue? The following works fine with oracle. I want to implement it inside a controller. DB::Raw did not work.

INSERT INTO TEMP (OBJECT_TYPE, OBLECT_ID)
SELECT DISTINCT HRP1001_CG.OBJECT_TYPE, HRP1001_CG.OBJECT_ID FROM HRP1001_SC, HRP1001_CG, CONFIG
WHERE
(HRP1001_SC.OBJECT_TYPE = 'CG')  
AND
(HRP1001_SC.REL_OBJ_TYPE = 'SC')   
AND
(HRP1001_SC.REL_OBJ_ID = CONFIG.SC)
AND
((HRP1001_SC.ST_DATE < CONFIG.DES_DATE) AND (HRP1001_SC.END_DATE > CONFIG.DES_DATE)) --ΗΜΕΡ/ΝΙΑ (ΜΕΤΑΓΕΝΕΣΤΕΡΗ ΤΟΥ ST_DATE KAI ΠΡΟΓΕΝΕΣΤΕΡΗ ΤΟΥ END_DATE
AND
(HRP1001_CG.REL_OBJ_ID = HRP1001_SC.OBJECT_ID)
AND
((HRP1001_CG.OBJECT_TYPE ='CG') OR (HRP1001_CG.OBJECT_TYPE ='SM'))
ORDER BY HRP1001_CG.OBJECT_ID;

My laravel implementation below gives me null or errors

        $data = DB::table('hrp1001_sc')
            ->join('config', 'hrp1001_sc.rel_obj_id', '=', 'config.sc')
            ->join('config', 'config.des_date', '>', 'hrp1001_sc.st_date')
            ->join('config', 'config.des_date', '<', 'hrp1001_sc.end_date')
            ->join('hrp1001_cg', 'hrp1001_cg.rel_obj_id', '=', 'hrp1001_sc.object_id') //errors with this line
            ->where('object_type', '=', 'cg')
            ->orwhere('object_type', '=', 'sm')
            ->distinct()
            ->get();

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

@TRAY2 - When just replacing raw with insert I get this error

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_PARSE)
syntax error, unexpected 'cg' (T_STRING), expecting ',' or ')'

And when replacing 'cg' with "cg" I get error again:

Error Code : 911 Error Message : ORA-00911: invalid character Position : 606 Statement : insert into temp (object_type, oblect_id) select distinct hrp1001_cg.object_type, hrp1001_cg.object_id from hrp1001_sc, hrp1001_cg, config where (hrp1001_sc.object_type = "cg") and (hrp1001_sc.rel_obj_type = "sc") and (hrp1001_sc.rel_obj_id = config.sc) and ((hrp1001_sc.st_date < config.des_date) and (hrp1001_sc.end_date > config.des_date)) and (hrp1001_cg.rel_obj_id = hrp1001_sc.object_id) and ((hrp1001_cg.object_type ="cg") or (hrp1001_cg.object_type ="sc")) order by hrp1001_cg.object_id; Bindings : [] (911)

I have started to wonder if it is possible to do it. I have tried many many combinations with no success...

18 Feb
3 months ago

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

@TRAY2 - I want to write a code like the following but gives me no results...

$data = DB::table('hrp1001_sc')
            ->join('config', 'config.sc', '=', 'hrp1001_sc.rel_obj_id')
            ->join('config', 'config.des_date', '>', 'hrp1001_sc.st_date')
            ->join('config', 'config.des_date', '<', 'hrp1001_sc.end_date')
            ->join('hrp1001_cg', 'hrp1001_cg.rel_obj_id', '=', 'hrp1001_sc.object_id')
            ->where('hrp1001_sc.object_type', '=', 'cg')
            ->where('hrp1001_sc.rel_obj_type', '=', 'sc')
            ->select('hrp1001_sc.object_id')
            //->distinct()
            ->get();

konrms left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel

@TRAY2 - At least for now I don't want to rename tables since they are directly used by my oracle database.

Although I do not get any error when running this query, my temp table doesn't populated (it should do however!). What else could I do?

DB::raw("insert into temp (object_type, oblect_id)
        select distinct hrp1001_cg.object_type, hrp1001_cg.object_id from hrp1001_sc, hrp1001_cg, config
        where
        (hrp1001_sc.object_type = 'cg')
        and
        (hrp1001_sc.rel_obj_type = 'sc')
        and
        (hrp1001_sc.rel_obj_id = config.sc)
        and
        ((hrp1001_sc.st_date < config.des_date) and (hrp1001_sc.end_date > config.des_date))
        and
        (hrp1001_cg.rel_obj_id = hrp1001_sc.object_id)
        and
        ((hrp1001_cg.object_type ='cg') or (hrp1001_cg.object_type ='sc'))
        order by hrp1001_cg.object_id;");
17 Feb
4 months ago

konrms started a new conversation How To Implement Oracle Query To Select From Different Tables In Laravel

I'm trying to select distinct from different tables in laravel. In oracle I have implemented successfully the query and works. Now I'm trying to "translate" it into laravel. How can I do that?

In oraclesql the query is the following. TEMP table exists as well as all other tables used in this query. Is it possible to do this with DB::raw? Could you give me your advice please?

INSERT INTO TEMP (OBJECT_TYPE, OBLECT_ID)
SELECT DISTINCT HRP1001_CG.OBJECT_TYPE, HRP1001_CG.OBJECT_ID FROM HRP1001_SC, HRP1001_CG, CONFIG
WHERE
(HRP1001_SC.OBJECT_TYPE = 'CG')  
AND
(HRP1001_SC.REL_OBJ_TYPE = 'SC')   
AND
(HRP1001_SC.REL_OBJ_ID = CONFIG.SC)
AND
((HRP1001_SC.ST_DATE < CONFIG.DES_DATE) AND (HRP1001_SC.END_DATE > CONFIG.DES_DATE)) 
AND
(HRP1001_CG.REL_OBJ_ID = HRP1001_SC.OBJECT_ID)
AND
((HRP1001_CG.OBJECT_TYPE ='CG') OR (HRP1001_CG.OBJECT_TYPE ='SM'))
ORDER BY HRP1001_CG.OBJECT_ID;
12 Feb
4 months ago

konrms left a reply on Oracle Authentication Using Laravel Authentication Scafolding Not Working

@TEMOSIS - TEMOSIS hi,

I am using Laravel Framework version 5.1.46 (LTS) with oracle db. I have connected database successfully and can run queries, store form data into db etc and oci8 is working fine. How can I protect one only route from access by unauthorized people?

So far I have just modified that route as below. What other files should be altered? Should I create authentication table in oracle for storing user credentials? Laravel documentation baffles me and I'm stuck at this point for many days. I have also opened a separate thread in laracasts but did not make it yet!

Route::get('/tabledata_id_title', '[email protected]') ->middleware('auth.basic');
09 Feb
4 months ago

konrms left a reply on Restricting Access To Laravel Site With Username And Password

@JLRDW - I was based heavily on this video on youtube https://www.youtube.com/watch?v=iKRLrJXNN4M&t=944s but after some point I lost myself...

konrms left a reply on Restricting Access To Laravel Site With Username And Password

@SNAPEY - I have the app\user.php. Is that what you mean?

<?php

namespace App;

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

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',
    ];
}

konrms left a reply on Restricting Access To Laravel Site With Username And Password

@SNAPEY - Hi Snapey! Thanks for replying!

So far I've watched some laracast video tutorials. From the very beginning I had difficulty in connecting my site with oracle database. I'm working on form projects mainly. I have created some forms that work fine. Now I want to restrict access to some management forms.

I edited my route according to the documentation you suggested. The route is the following:

Route::get('/tabledata_id_title', '[email protected]') ->middleware('auth.basic');

Now, regarding the auth.php file, how should I modify it so as the correct credentials for opening /tabledata_id_title to be those existing into my oracle ADMINS table? The ADMINS table is consisted of two fields (email and pass).

My auth.php is the following:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    |
    | This option controls the default authentication "guard" and password
    | reset options for your application. You may change these defaults
    | as required, but they're a perfect start for most applications.
    |
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session", "token"
    |
    */

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    |
    | You may specify multiple password reset configurations if you have more
    | than one user table or model in the application and you want to have
    | separate password reset settings based on the specific user types.
    |
    | The expire time is the number of minutes that the reset token should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];