newbie360

Experience

8,950

9 Best Reply Awards

  • Member Since 1 Year Ago
  • 3 Lessons Completed
  • 1 Favorite

18th August, 2018

newbie360 left a reply on Best Practice For Naming Your Sub Folders In The "views" Folder • 8 hours ago

mailing.list is confuse with views/mailing/list.blade.php or views/mailing.list.blade.php

i will use mailing_list.blade.php

newbie360 left a reply on How To Change School_id To A Int For Save In Database? • 8 hours ago

may be just like this ?

<script type="text/javascript">
    $("#schools").submit(function (event) {
        event.preventDefault();
        province_id = $('#province_id').val();
        city_id = $('#city_id').val();
        center_id = $('#center_id').val();
        school_id = $('#school_id').val(); // you need modify this, how to assign the value
        
        $.post("{{ route('schools-list.store') }}", {
            province_id:province_id, 
            city_id:city_id, 
            center_id:center_id, 
            school_id:school_id
        });
    });
</script>

newbie360 left a reply on Share The Code Between Store And Update • 8 hours ago

i didn't start to write any code, i just thinking if i can pass the request and model like this

newbie360 started a new conversation Share The Code Between Store And Update • 9 hours ago

my create and edit view is include the same template form

now i want in controller to share the duplicate code between store and update

as you can see the duplicate code is same as in store and update

// controller
public function store(BookRequest $request)
{
    $book = new Book;

    // duplicate code
    $book->title = $request->input('title');
    $book->author = $request->input('author');
    $book->save();

    return redirect()->route('book.show', $book);
}

public function update(BookRequest $request, Book $book) // Route Model Binding
{
    // duplicate code
    $book->title = $request->input('title');
    $book->author = $request->input('author');
    $book->save();

    return redirect()->route('book.show', $book);
}

so can i pass the request and model like this to use the duplicate code?

// controller
public function store(BookRequest $request)
{
    $book = $this->saveBook($request, (new Book));
    return redirect()->route('book.show', $book);
}

public function update(BookRequest $request, Book $book)
{
    $book = $this->saveBook($request, $book);
    return redirect()->route('book.show', $book);
}

private function saveBook($request, $model)
{
    $model->title = $request->input('title');
    $model->author = $request->input('author');
    $model->save();
    return $model;
}

15th August, 2018

newbie360 left a reply on Store Image In Public/storage And Get The Path For Database • 3 days ago

the second param public is the disk name, means save to public disk

$path = $request->file('file')->store('user/1', 'public');

newbie360 left a reply on Store Image In Public/storage And Get The Path For Database • 3 days ago

if this didn't work, hmm no idea where the word 'profile' from

$path = $request->file('file')->store('user/1', 'public');

newbie360 left a reply on How To Create A Search Result Page With Multiple Queries • 3 days ago

yep as @Cronix say, if use GET method, the variable= in the query string is not affect your backend code, because in your backend code should check the variable

newbie360 left a reply on Store Image In Public/storage And Get The Path For Database • 3 days ago

weird, can you show config/filesystems.php file

newbie360 left a reply on How To Create A Search Result Page With Multiple Queries • 3 days ago

you may try use POST method in the

newbie360 left a reply on How To Create A Search Result Page With Multiple Queries • 3 days ago

if you means the pagination link showing the &min_price=&maxprice=&bedrooms=&bathrooms= and you don't want it

may be do something like this

public function search_page(Request $request)
{
    // validation ...

    $query = YourModel::query();
    $queryStr = [];
    
    if ($city = $request->input('city') ?? '')
    {
        $query->where('city', $city);
        $queryStr['city'] = $city;
    }

    if ($type = $request->input('type') ?? '')
    {
        $query->where('type', $type);
        $queryStr['type'] = $type;
    }
    
    $result = $query->orderBy('id', 'asc')->paginate(20);
    $result->appends($queryStr);
}

newbie360 left a reply on Store Image In Public/storage And Get The Path For Database • 3 days ago

what about change to

$path = $request->file('file')->store('user/1');

newbie360 left a reply on Store Image In Public/storage And Get The Path For Database • 3 days ago

you stored user/1/7a6K0YfRgCbBhakkbbnOr2kx5p4LUfM72QSaYmu2.jpeg in db ?

if yes

return Storage::url($user->picture_path);

newbie360 left a reply on How To Create A Search Result Page With Multiple Queries • 3 days ago

i don't understand all about the {!! Form::...... !!} because is not documented in 5.6

so i try and guess

public function search_page(Request $request)
{
    // validation ...

    $query = YourModel::query();

    if ($city = $request->input('city') ?? '')
    {
        $query->where('city', $city);
    }

    if ($type = $request->input('type') ?? '')
    {
        $query->where('type', $type);
    }
    
    $result = $query->orderBy('id', 'asc')->paginate(20);
}

newbie360 left a reply on Variable Passed From Serviceprovider Not Available In App.blade.php • 3 days ago

the path of the app.blade.php is resources/views/app.blade.php ?

newbie360 left a reply on Dynamic Config • 3 days ago

well i'm confuse now xD

if any reason you don't want hardcored in config/app.php

//'timezone' => 'UTC',
'timezone' => 'America/Chicago',

so you may do this in AppServiceProvider

    public function boot()
    {
        config(['app.timezone' => 'America/Chicago']);
    }

and if any reason still not fit your case, put it in controller __construct() ?

// YourController
    public function __construct()
    {
        config(['app.timezone' => 'America/Chicago']);
    }

newbie360 left a reply on Dynamic Config • 3 days ago

i think he want load the config from db instead of config/myconfig.php

so he may have a view for edit config in admin panel

i don't know if this is still work

https://stackoverflow.com/questions/32824781/laravel-load-settings-from-database

newbie360 left a reply on Forms Empty On Redirect • 3 days ago

value="{{ old('reasorce', $reasorce->property ?? '') }}"

newbie360 left a reply on Fetch Data From Controller And Display In Table View • 3 days ago

your form like this ?

<form method="POST" action="/devoteeSearch">
    @csrf

and try

public function search(Request $request)
{
    dd('never get there');

search again, did you see never get there ?

newbie360 left a reply on Fetch Data From Controller And Display In Table View • 3 days ago

i don't know if this is what you want

public function search(Request $request)
{
    // $UserName = $request->input('devoteeName');
    // if submit devoteeName is empty, Laravel will change to null
    // so if($UserName != ""){ <= this is wrong

    $UserName = $request->filled('devoteeName') ? $request->input('devoteeName') : null;
    
    if (! empty($UserName))
    {
        $devotee = Devotee::where ( 'NAME', 'LIKE', '%' . $UserName . '%' )->get (['id','NAME','CONTACT','TEMP_ADDRESS']);

        // you should use redirect instead view after POST data, prevent user reload the page submit again
        // but i don't know why use POST on query get data from db, may be you has another code after this block

        // ok if you want use view
        return view( 'pages.devoteeSearch' ,compact('devotee'));
    }
    
    // look like u have other code below here reuse the $UserName ....
}

//devoteeSearch.blade.php

@if (blank($devotee))
    <div class="alert alert-danger" role="alert">
        Sorry No details found
    </div>
@else
<table id="books" class="table table-bordered gridview">
        <thead>
            <tr>
                <th>BOOK ID</th>
                <th>BOOK NAME</th>
                <th>UNIT PRICE</th>
                <th>EDIT</th>
            </tr>
        </thead> 
        <tbody>
            @foreach($devotee as $data)
             <tr>
                 <td> {{$data->NAME}} </td>
                 <td> {{$data->CONTACT}} </td>
                 <td> {{$data->TEMP_ADDRESS}} </td>
            </tr>
        </tbody>          
</table>
@endif

newbie360 left a reply on Fetch Data From Controller And Display In Table View • 3 days ago

@scala first, i'm same with you is not a experience programmer xD, because i'm newbie360

hmmmmm but i know if the first step wrong , all the following step may be wrong too

i saw many member post code in this forum, write 100 lines at a time, but actually the first step is wrong, so need to change the whole code block logic

for me....

step1, the return is expected ?

int ? string ? array ? object ? i will keep ask myself what if return is empty / null ? define default value ?

most time use dd($variable) to debug before you do the step2

if you sure the return is expected, then write the step2 code

step3

step4

step5

newbie360 left a reply on Fetch Data From Controller And Display In Table View • 3 days ago

if you followed the answser by @Snapey

            @forelse($devotee as $data)
             <tr>
                 <td> {{$data['NAME']}} </td>
                 <td> {{$data['CONTACT']}} </td>
                 <td> {{$data['TEMP_ADDRESS']}} </td>
            </tr>
            @empty
             <tr>
                 <td colspan="3">no data</td>
            </tr>
            @endforeach

newbie360 left a reply on Fetch Data From Controller And Display In Table View • 3 days ago

also you need to check if $devotee is exists, the second return didn't pass $devotee

newbie360 left a reply on Fetch Data From Controller And Display In Table View • 3 days ago

also if reirect to

return view ( 'pages.devoteeSearch' )->with('alert-danger', 'Sorry No details found');

you will get an error too, because in the blade you may need to check $devotee is exists

newbie360 left a reply on Paginate - Items Per Page • 3 days ago

<form class="form-inline" method="GET" action="{{ route('type you route here') }}" role="form">
            <div class="form-group">
                            <label for="perPage">Example select:  </label>
                            <select class="form-control" id="perPage" name="perPage">

                                <!-- all option missing value="" -->
                                <option>5</option>
                                <option>10</option>
                                <option>15</option>
                                <option>20</option>
                                <option>25</option>
                            </select>
           </div>
</form>

after modifyed the form, check all the variable is passed to your index

public function index(TaskRepository $taskRepo)
{
    dd($request->all);

14th August, 2018

newbie360 left a reply on Paginate - Items Per Page • 4 days ago

missing form action ?

newbie360 left a reply on Joining/Merging/Combining JSON Data • 4 days ago

array_flatten() or array_collapse() ?

newbie360 left a reply on How To Use Exists Validation In Laravel With OR • 4 days ago

https://laravel.com/docs/5.6/validation#custom-validation-rules

so you can use like this

use App\Rules\Uppercase;

$request->validate([
    'name' => ['required', 'string', new Uppercase],
]);

newbie360 left a reply on Search MySQL Database And Sort By Relevancy? • 4 days ago

lol no idea, may be give a radio option in the search form

<input type="radio" name="search_mode" value="normal"> High accuracy (less result)
// searchKey = 'marketing director'
// and use ("marketing director" IN BOOLEAN MODE)

<input type="radio" name="search_mode" value="wide"> Low accuracy (more result)
// searchKey = 'marketing director'
// and use ("*marketing*director*" IN BOOLEAN MODE)

13th August, 2018

newbie360 left a reply on Search MySQL Database And Sort By Relevancy? • 5 days ago

oops i think if you search with this, you will see the difference

SELECT *, MATCH (title) AGAINST ("*marketing*director*" IN BOOLEAN MODE) as score
FROM table_name
ORDER BY score DESC

newbie360 left a reply on Search MySQL Database And Sort By Relevancy? • 5 days ago

because i don't know what is elasticsearch, so i asked the question ;(

newbie360 left a reply on Search MySQL Database And Sort By Relevancy? • 5 days ago

can i ask why don't use fulltext search ?

SELECT *, MATCH (title) AGAINST ("*Director*" IN BOOLEAN MODE) as score
FROM table_name
ORDER BY score DESC

newbie360 left a reply on How To Change School_id To A Int For Save In Database? • 5 days ago

i don't understand ;(

where the data_school.id from ?

var school_id = {school_id: data_school.id} ;

newbie360 left a reply on How To Use Exists Validation In Laravel With OR • 5 days ago

something like this ?

$validator = Validator::make($data, [
    'messages_receiver' => [
        function($attribute, $value, $fail) {
            if (\DB::table('users1')->where('user_id', $value)->doesntExist() &&
                \DB::table('users2')->where('user_id', $value)->doesntExist()) {
                return $fail($attribute.' is invalid.');
            }
        },
    ],
]);

newbie360 left a reply on Trying To Get Property 'first_name' Of Non-object • 5 days ago

oops my mistake, yea array returned

newbie360 left a reply on Upgrade To PHP 7.2 Caused Error In Function Counting Form Input Array • 5 days ago

i think you need re-view all the code again, because in difference system, don't know if this help

array_wrap($this->input('photos'));

newbie360 left a reply on Trying To Get Property 'first_name' Of Non-object • 5 days ago

Employee Data Page = punch.blade.php ?

what about $employee is null ?

$employee = DB::select('SELECT * FROM `employees` WHERE (RIGHT(ssn,6)) = "'.$request->clock_id.'" limit 1');

newbie360 left a reply on Redirect My Project To Dashboard • 5 days ago

no idea why redirect to http://me.test/dashboard/

are you setup a virtual host named me.test before ?

open your windows cmd, and type

ipconfig /displaydns

see any about me.test there ?

try change your virtual host ServerName localhost.abc

and restart the server

newbie360 left a reply on Problem In Pagination After Ajax Return In Laravel • 5 days ago

public function search_excess_milk_details( Request $request )
{               
    $searchTime = $request->filled('search_time') ? $request->query('search_time') : null;
    $query = Excess_milk::query();

    if (!empty($searchTime))
    {
        $query->Where('time', 'LIKE', '%' . $searchTime . '%');
    }

    $xcess_milks = $query->orderBy('date', 'asc')->paginate(5);

    if (!empty($searchTime))
    {
        // append the query string, eg, http://localhost/something?search_time=searchTime
        $xcess_milks->appends(['search_time' => $searchTime]);
    }

   return Response($xcess_milks);
}

and view

@if ($xcess_milks->hasPages()) {{ $xcess_milks->links() }} @endif

this just an example, you need modify by yourself

newbie360 left a reply on How Can I External Directory Than Laravel Project Directory? • 5 days ago

the app is used on your own server only, so you can change any system config ?

12th August, 2018

newbie360 left a reply on How To Deal With Dependency Injection With Dynamic Parameters In The Constructor? • 6 days ago

$cls is dynamic meaning like this ?

class SomeClass {
   public function __constructor(AnotherClass ...$cls) {...}
}

newbie360 left a reply on Possible Store New Record And Save The Inserted Id In To Same Row Other Column Same Time? • 6 days ago

yea, but what about if the $doc_path is something like this

/2018/01/02/staff_code/client_id/maybe_more/contract_id

too much calculation when use accessor

newbie360 left a reply on Possible Store New Record And Save The Inserted Id In To Same Row Other Column Same Time? • 6 days ago

oh yea, this will work i guess, but still need two query, thanks so much

$contract->timestamps = false;
$contract->doc_path = '2018-01-02__' . $contract->id;
$contract->save();

newbie360 left a reply on Possible Store New Record And Save The Inserted Id In To Same Row Other Column Same Time? • 6 days ago

@Cronix Are you saying you want to create a new contract, and use that new contracts id to insert in the same contract in a single step?

yes

because for the performace, i don't want any extract action to get the $doc_path

actually the $doc_path not as simple just a date__id

newbie360 left a reply on Possible Store New Record And Save The Inserted Id In To Same Row Other Column Same Time? • 6 days ago

@wilk_randall but this will changed the updated_at column ?

newbie360 started a new conversation Possible Store New Record And Save The Inserted Id In To Same Row Other Column Same Time? • 6 days ago

for example:

public function store(Request $request)
{
    Contract::create([
        'name' => 'name',
        'doc_path' => '2018-01-02__' . $id, // how to save inserted new record $id to this column at the same time ?
    ]);

    return back();
}

i know can query the Auto Increment Id by use

// Contract model
public static function getAutoIncrementId()
{
    $tableStatus = DB::select("show table status where Name = '" . (new static)->getTable() . "'");
    return $tableStatus[0]->Auto_increment;
}

but should i trust this value at the runtime?

newbie360 left a reply on Cannot Display Image File To Index Page, Using The Edit/update Method • 6 days ago

when you view the html source code in browser, all correct ?

<img class="img-responsive" width="30%" src="/storage/cover_images/the_image_name.jpg" alt="">

also type the url of the image in browser, see the image ? or you forgot make the symlink ?

newbie360 left a reply on Cannot Display Image File To Index Page, Using The Edit/update Method • 6 days ago

did you put <form ........ enctype="multipart/form-data"> ?

11th August, 2018

newbie360 left a reply on Datatable Server Side Processing • 1 week ago

after go to that page, ok start loading......, all i care is after me dead, no one come to click the browser stop button on my computer. so sad, can't see the page content when i still alive

newbie360 left a reply on Why Laravel Returning Select Count(*) After Update ? • 1 week ago

after update/delete, will return the affected rows count

$counts = Model::delete([1,2,3]); // $counts = 3

or just simple doing this ?

Model::delete([1,2,3]);

newbie360 left a reply on Why Laravel Returning Select Count(*) After Update ? • 1 week ago

your can use only() , except() get the array first

$input = $request->only(['username', 'password']);

$input = $request->only('username', 'password');

$input = $request->except(['credit_card']);

$input = $request->except('credit_card');

or did you set this in your model

protected $guarded = [];

// or

protected $fillable = [];
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.