Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by osherdo

  1. @Jackues1 ok I get you. Well I think the accurate question I wanted to ask for this specific thread,regardless of Laravel framework - How can I reuse a php method (suppose it contains the logic for authenticating a user) in a function?
  2. @Jacques1 thanks for that. So I understood the quoted part from your reply, and I think I may have misunderstood you.
  3. @OrpheanBeholderScryDoubt I think the second solution will be better. I still don't get why I will need to call the method in the constructor as well. @Dark Administrator this is what I am trying to figure
  4. I am using Laravel framework. I want to authenticate a user on all functions available in my code. I did not understood the constructor method quite right, and the docs were hard to follow as well. Assuming I have this code: public function __construct() { // Constructor for checking user's auth after a while. $this->middleware('auth'); if (!Auth::check()) { return redirect('auth/login'); } function something() { // How do I call it to work inside this function? } Thanks for helping.
  5. @OrpheanBeholderScryDoubt thanks for the suggestion and reference. Good to know about it.
  6. unfortunately using this: [] returns an error: syntax error, unexpected '[', expecting '('
  7. It seems that only this works: public function authorize($ability, $arguments = array()) because using the other one, or using them both as an arguments returns this error: (I am using Laravel, and it returns this) Declaration of App\Http\Controllers\DropzoneController::authorize() should be compatible with App\Http\Controllers\Controller::authorize($ability, $arguments = Array) I am now getting an error of Laravel, so that'll do for now. much thanks!
  8. I have this code: class DropzoneController extends Controller { public function __construct() { $this->middleware('auth'); if (!Auth::check()) { return redirect('auth/login'); } $this->user = Auth::user(); } public function index() { return view('dropzone_demo'); } public function uploadFiles() { $message="Profile Image Created"; $input = Input::all(); $rules = array( 'file' => 'image|max:3000', ); $validation = Validator::make($input, $rules); if ($validation->fails()) { return Response::make($validation->errors->first(), 400); } $destinationPath = 'uploads'; // upload path: public/uploads $extension = Input::file('file')->getClientOriginalExtension(); // getting file extension $fileName = rand(11111, 99999) . '.' . $extension; // renameing image $upload_success = Input::file('file')->move($destinationPath, $fileName); // uploading file to given path if ($upload_success) { return Response::json('success', 200); } else { return Response::json('error', 400); } // attaching the profile image to the authenticated user. $user->profileImage()->create([ 'filename' => $filename ]); Session::flash('new_profile_image', 'Profile Photo Updated!'); } public function authorize($ability, $arguments = Array) { // set to true instead of false return true; } } The error occurs for this line: public function authorize($ability, $arguments = Array) and it says: syntax error, unexpected ')', expecting '(' Not sure what that means. Anyone who can tell me what the issue is?
  9. ignore it, I have mistakenly tried to insert to the same id that already existed, and it thrown an error.
  10. I am trying to insert multiple rows to a column in mysql like this: INSERT INTO `sportsapp`.`exercises` (`id`, `image_path`, `name`, `category`) VALUES ('3', 'exercises/biceps/barbell_curls_lying_against_an_incline.jpg', 'Barbell Curls Lying Against An Incline', 'Biceps'), ('4','exercises/biceps/cable_hammer_curls_-_rope_attachment','Cable hammer Curls - Rope Attachment','Biceps'); I am getting an error in return: I tried to google and understand what's the reason for it, but I dont get it. I do have already a primary key, and I don't know why it generates another primary key, Could you please try to help with this?
  11. I was found out why : Next: within these: {{!! !!}} I need to comment the {{!! !!]] with the blade syntax comment: {{-- --}} around it. Solved.
  12. I am getting this error: syntax error, unexpected '}' @extends('layouts.master') @section('scripts') <script type="text/javascript" src="{!! asset('js/status.min.js') !!}"></script> @stop @section('content') {!! csrf_field() !!} @if (count($errors) > 0) <div class="alert alert-danger"> <strong>Whoops!</strong> There were some problems with your input.<br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <!-- Using laravel session --> @if(Session::has('message')) <!-- Checking if session has a variable called message. --> <div class="alert alert-info"> <li> {{ Session::get('message') }} </li> <!--if true -print the message from the insert_posts variable. --> </div> @endif {{-- You have a $user variable available representing the current Auth::user(); --}} <p>Hello, {{ $user->name }}.</p> {{-- This user has a profile whose properties you can also display --}} <p>Goals: {{ $user->profile->goals }}</p> {{-- You can also drill down to the profile's expectations --}} <p>Expectations</p> <ul class="profile-list"> @foreach($user->profile->expectations as $expectation) <li class="profile-list-item">{!! $expectation->name !!}</li> @endforeach </ul> <p><b> this is other users you may want to follow: </br></p> <ul> @foreach($mutuals as $mutual) <!-- hub/{{$mutual->user->id}} It goes to the user that matches the value of $mutual criteria. and then it goes and gets its id.This is sent to the controller for further handling.Check page source to see id's numbers. --> <!-- In the href - Passing the user to your controller --> <br><li><a href="{{URL::to('hub', [$mutual->user->id])}}" class="button button-3d" name="make_follow">Follow User</a> {!! $mutual->user->name; !!} <!-- I access the user's name property --> </li> @endforeach </ul> <form action="{{ route('createPost') }}" method="post"> <!--the form action is the method in a route called createPost --> @if(isset($message)) <!-- if the var exist and have a value it would be printed. It is used for all the notifications in this page.--> {{ $message }} @endif <br> <!-- only when a post has been submitted the varible value will show. --> <!-- telling the form the info go to this route (url). almost equal form action ="samePage" --> {!! Form::hidden('post') !!} {!! csrf_field() !!} <div class=contentWrap> <div class="test" placeholder="How's your fitness going?..." contenteditable="true"></div> </div> <div class=icons> <img alt="heart" src="http://icons.iconarchive.com/icons/succodesign/love-is-in-the-web/512/heart-icon.png"> </div> <button> Post to profile </button> <div class="errors"> </div> </form> <!-- script to check if user typed anything in the textbox before submit. both .text() and .html() return strings. It's testing if the string length is zero. trim is for removing whitespaces before and after a string. the 'submit' event is needed since it's a submit button. --> <div class="own_posts"> <p> here are your latest posts:</p> <!-- I think I should create foreach loop to iterate over each post and show it here. --> </div> <br><br> <div class="following_posts"> <p> Posts from people you're following: <p> <!-- Iterate over the followee's posts with a foreach loop: the first parameter the foreach gets is the array expression. Second element: On each iteration, the value of the current element (which is a post) is assigned to $value (second element) and the internal array pointer is advanced by one. Next: within these: {{!! !!}} --> @foreach ($get_followee_posts as $post) <form action="/html/tags/html_form_tag_action.cfm" method="post"> <textarea name="comments" id="comments" style="width:96%;height:90px;background-color:white;color:black;border:none;padding:2%;font:22px/30px sans-serif;"> {!! $post->full_post !!} </textarea> </form> @endforeach </div> @stop I tried with 2 editors and netbeans to figure why. I also use blade syntax of laravel.
  13. @Psycho are you familiar with laravel by accident?
  14. public function mutual() { $mutualUsers = DB::table('expectation_profile')->where(expectation_id,); } I am trying to write the query now. Not done with it yet.
  15. I have this pivot table: http://3.1m.yt/0_7a5sa.png I need to return multiple names of users (from users table) that have at least one expectation_id value as the current user have. How do I achieve that? Do I need to iterate with foreach loop and use Auth::user() to do this? Thanks.
  16. Got it figured out eventually. thanks for your honest opinions. https://3v4l.org/JFvt7 - working example.
  17. @QuickOldCar I am not sure I got what your'e trying to say. anyway here's a screenshot of how it did look when posting this problem here: http://4.1m.yt/8qLiQI9.png and after I changed the code to look like this - calling the unset method explicitly it now shows it properly: (I post the second class only for convenience): class MyOtherClass extends MyClass { public function __construct() { echo "A new constructor in " . __CLASS__ . ".<br />"; } public function newMethod() { echo "From a new method in " . __CLASS__ . ".<br />"; } } // Create a new object $newobj = new MyOtherClass; // Output the object as a string echo $newobj->newMethod(); // Use a method from the parent class echo $newobj->getProperty(); unset($newobj); generate messsage on browser. ?> And now it shows well: http://i63.tinypic.com/x4g4tc.png
  18. Okay I think I almost got it. Now it shows a warning in the output. can you tell me what's wrong here? https://3v4l.org/k390G Thanks.
  19. I am trying to return the unset method (with the __destruct function) but it only returns the error at the top of th page and not at the bottom as it should be. Can you tell me how do I return it in the bottom please? here's my code:
  20. Please here's the entire code for you to review: https://3v4l.org/MSWq6 would like to hear your opinion. why cannot I initiate the second class ?
  21. I am actually using Laravel 5.1. you think it would be better to ask in a laravel's forum? I did posted partial code.
  22. Consider this code: <?php class MyClass { public $prop1 = "I'm a class property!"; public function setProperty($newval) { $this->prop1 = $newval; } public function getProperty() { return $this->prop1 . "<br/>"; } } $obj = new MyClass;// Class instantiation. //var_dump($obj); echo "1st drill:"."<br>"; echo $obj->getProperty(); //echo prop1 string (// Get the property value). $obj->setProperty('I am a new property value'."<br><br>"); echo $obj->getProperty(); // Read it out again to show the change. //Second Drill echo "second drill: "."<br>"; class class2 { public $obj2="I am the first variable from the second drill."; public function setProperty2($newval2) { $this->obj2=$newval2; } public function getProperty2($newval2) { return $this->obj2."<br>"; } } // Create two objects $obj = new class2; $obj2 = new class2; When trying to create two objects in the second drill (the last 2 rows) - it returns an error: FatalErrorException in oop.php line 41: Call to undefined method class2::getProperty() why can't I initiate the class?
  23. I am trying to pick activityType and show the value in an array that looks like this: http://4.1m.yt/ukCLELP.png I want the activityType value to be an actual option like: option1,option2 etc.. But it throws an error instead (when trying to change values of it): ErrorException in c3b8369e5906a262c6e3760a4e5a65e9 line 35: Use of undefined constant Aerobics - assumed 'Aerobics' (View: /var/www/L53/resources/views/dashboard.blade.php) here's my relevant view code snippet: ) What do you expect from this app to help you? <br><br> (You can always change this later) <br><br> &nbsp{!! Form::checkbox('expectations','New anerobic routines'); !!} Find new anerobic routines <br> &nbsp{!! Form::checkbox('expectations','New aerobic routines'); !!} Find new aerobic routines <br> &nbsp{!! Form::checkbox('expectations','Follow'); !!} Follow other users to get inspired <br> <br><br> Thanks!
  24. Hi I am wondering what this code snippet means. I would appreciate you help ,please. Please note that it is taken from Laravel's website. (written in a bit different php code). public function index() { $flights = Flight::all(); return view('flight.index', ['flights' => $flights]); } } Thanks.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.