Laravel 5 - Rest - rest

Good morning,
I'm working on a laravel 5 social-network-like app and I'm trying to use Restfull controllers but I've found a problem
How can I avoid the resource for the user?
I mean, how can I do this:
Route::resource('{username}', 'UserController');
instead of this:
Route::resource('user/{username}´, 'UserController');
The first one takes me to index method inside UserController, but it must take me to show method, taking {username} as the id parameter.
Therefore I would make nested resources like
// user's photos index
Route::resource('{username}/photos´, 'UserPhotosController');
// show one photo (photo_id)
Route::resource('{username}/photos/photo_id´, 'UserPhotosController');
Any ideas?

When defining this: Route::resource('{username}', 'UserController');
These are the routes that get generated by Laravel:
| GET|HEAD | {username} | {username}.index | UserController#index |
| GET|HEAD | {username}/create | {username}.create | UserController#create |
| POST | {username} | {username}.store | UserController#store |
| GET|HEAD | {username}/{{username}} | {username}.show | UserController#show |
| GET|HEAD | {username}/{{username}}/edit | {username}.edit | UserController#edit |
| PUT | {username}/{{username}} | {username}.update | UserController#update |
| PATCH | {username}/{{username}} | | UserController#update |
| DELETE | {username}/{{username}} | {username}.destroy | UserController#destroy |
This table shows that the /{username} route will go to the UserController#index method. Also, If you notice, the show route that gets generated is actually:
{username}/{{username}}
Therefore I wouldn't suggest to use the Resource route generator, instead is best if you defined the routes in an explicit manner. For example:
Route::get('{username}', ['as' => 'username.show', 'uses' => 'UserController#show']);
Also, Laravel reads the routes in the order that they appear. When you define such dynamics routes, make sure that this routes are the last one in your route.php file. Example:
Route::get('about', 'StaticPagesController#about');
Route::get('blog', 'StaticPagesController#blog');
Route::get('contact', 'StaticPagesController#contact');
Route::get('{username}', ['as' => 'username.show', 'uses' => 'UserController#show']);

Related

SQL parameter table

I suspect this question is already well-answered but perhaps due to limited SQL vocabulary I have not managed to find what I need. I have a database with many code:description mappings in a single 'parameter' table. I would like to define a query or procedure to return the descriptions for all (or an arbitrary list of) coded values in a given 'content' table with their descriptions from the parameter table. I don't want to alter the original data, I just want to display friendly results.
Is there a standard way to do this?
Can it be accomplished with SELECT or are other statements required?
Here is a sample query for a single coded field:
SELECT TOP (5)
newid() as id,
B.BRIDGE_STATUS,
P.SHORTDESC
FROM
BRIDGE B
LEFT JOIN PARAMTRS P ON P.TABLE_NAME = 'BRIDGE'
AND P.FIELD_NAME = 'BRIDGE_STATUS'
AND P.PARMVALUE = B.BRIDGE_STATUS
ORDER BY
id
I want to produce 'decoded' results like:
| id | BRIDGE_STATUS |
|--------------------------------------|------------ |
| BABCEC1E-5FE2-46FA-9763-000131F2F688 | Active |
| 758F5201-4742-43C6-8550-000571875265 | Active |
| 5E51634C-4DD9-4B0A-BBF5-00087DF71C8B | Active |
| 0A4EA521-DE70-4D04-93B8-000CD12B7F55 | Inactive |
| 815C6C66-8995-4893-9A1B-000F00F839A4 | Proposed |
Rather than original, coded data like:
| id | BRIDGE_STATUS |
|--------------------------------------|---------------|
| F50214D7-F726-4996-9C0C-00021BD681A4 | 3 |
| 4F173E40-54DC-495E-9B84-000B446F09C3 | 3 |
| F9C216CD-0453-434B-AFA0-000C39EFA0FB | 3 |
| 5D09554E-201D-4208-A786-000C537759A1 | 1 |
| F0BDB9A4-E796-4786-8781-000FC60E200C | 4 |
but for an arbitrary number of columns.

Swift & Firebase - Split data for user info?

I currently coding a fitness app that permits to record all the personal records for a user.
I'm really new with Cloud Firestore from Firebase, so I really don't know how I could structure the database.
In my mind, I have two options:
OPTION 1
Users
|
+--UserID
| |
| +--Name
| +--Phone
| +--etc..
|
|
Users-records
|
+--UserID
| |
| +--RecordName
| | |
| | +--recordValue
| | +--recordType
| |
| +--RecordName
| | +--recordValue
| | +--recordType
OPTION 2
Users
|
+--UserID
| |
| +--Name
| +--Phone
| +--etc..
| +--Records
| | |
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
The questions are: Do I have to split the collection for the user?
Do you think this architecture is well designed for the purpose (ie record personal records from users)?
Thank you very much
Your database structure really depends on how you are going to use it. Keep in mind that whenever you observe a node, you are also observing all of the children nodes.
So I'd probably go with something closer to Option two, maybe like this:
Users
|
+--UserID
| |
| +--UserInfo
| | |
| | +--Name
| | +--Phone
| | +--etc..
| |
| +--Records
| | |
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
I'd choose this, because I'd image you'd want to get all of the UserInfo at once, So we can observe that "UserInfo" node and get all of the children: name, phone, etc....
Then I'd think you'd also want to get all of the records at once, so we can observe that "Records" node and get all of that data.
Additionally, if you wanted, you could get everything at once by observing the UserID!
However, if you were maybe going to be getting a list of all the users, then you definitely don't want all this data in one spot and this design wouldn't work, because that is a lot of data to observe just to get all the users.
In summary: Choose an option which makes it easiest for you to get what you need, without getting extra data you don't want!

How do I import groups from graphml file? (networkx -> cytoscape)

I'm trying to bring networkx data into cytoscape. I'm using graphml and that part is fine, but I have an attribute parent=node_name that I want to establish a group with. I cannot find out how to map this in cytoscape. Any ideas on how to automatically create groups in cytoscape?
Example:
G = nx.Graph()
G.add_node("server1")
G.add_node("server1_port1", parent="server1")
G.add_node("server1_port2", parent="server1")
G.add_node("server2")
G.add_node("server2_port1", parent="server2)
G.add_node("server2_port2", parent="server2)
G.add_edge("server1_port1", "server2_port1")
nx.write_graphml(G, "output.graphml")
It should look something like this:
+-----------------+
| server1 |
| |
| {port1} {port2} |
| ~ |
| | |
+----|------------+
|
+----|------------+
| server2 |
| | |
| ~ |
| {port1} {port2} |
| |
+-----------------+
Unfortunately, our GraphML reader doesn't support groups -- I can think of ways to do this semi-automatically, but I'm not sure that's what you want. What you would need to do is to add an attribute to each of your nodes (e.g. "parent") and then create the groups using that attribute (the setsApp will help you do that). Once you've created the groups, use the Compound Node visualization to get the look you want.
-- scooter

What is a common REST way to request a list of resources that all exclude a propert, like an outer join

For my specific case, I have users which can be friends with each other.
I have a users table:
| Id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
And a friends table:
| Id | From_User_Id | To_User_Id |
+----+--------------+------------+
| 1 | 1 | 2 |
| 2 | 3 | 1 |
And I want to get all users NOT friends with a user. So for User 1 the result returned will be User 4.
What should a REST GET request look like to retrieve this list?
You could do:
GET /users/1/notfriends
The important point is however, that the representation at /users/1 should link to this to be "proper" REST.

What is the best way to "paginate" a loooong SVG file on iOS?

I am facing an interesting problem with SVG and iOS.
I need to render very long SVG files (up to about 5mb large), which hasn't been a problem using UIWebView. I also haven't had a problem scrolling them smoothly with JS, but since I'm waiting on my developer program application to be approved I haven't tested the performance on an actual device.
I'm now trying to achieve a page-turning effect like how the iBooks app flips pages. It doesn't have to be as elaborate and intricate, the gist of the idea is that the next section of the svg will "wipe over" the last.
Reason being, I need both "pages" of content to remain static to ease the reading of the content during the "flipping" process. Scrolling very quickly makes the contents of the SVG difficult to read.
Here is a graphic representation of what I would like to achieve:
---------------------------
| |
| |
| |
| 1 |
| |
| |
| |
| |
---------------------------
---------------------------
| | |
| | |
| | |
| 2 | 1 |
| |-> |
| | |
| / |
| / |
---------------------------
---------------------------
| | |
| | |
| | |
| 2 | 1 |
| |-> |
| | |
| / |
| / |
---------------------------
---------------------------
| |
| |
| |
| 2 |
| |
| |
| |
| |
---------------------------
Looking forward to some interesting ideas from you veterans!
I haven't rut to such needs, but from what I know, it could be made by two UIViews (or any of their subclasses). All you have to do is a custom animation on flip(a simple one if you interested in flip only, a harder one if you need the animation actually to go one with the finger). And of course you'll need to put corresponding part of your file to those views. Actually I would suggest using 3 views, so you'll be able to put content of the next "page" while it still offscreen. That will make your animation smoother.